我是一名新的iphone开发者。如何在图像视图中上传图像,该图像取自相机和照片库。
感谢所有人。
答案 0 :(得分:2)
试试这个。
- (IBAction)m_CtrlBtn_SelectImage_click:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
// Set source to the Photo Library
imgPicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;// imgPicker is a UIImagePickerController object;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
self.popoverController = popover;
[popover release];
// popoverController.delegate = self;
[popoverController presentPopoverFromRect:CGRectMake(0, 0, 500, 480) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[imgPicker release];
}
else
{
[self presentModalViewController:self.imgPicker animated:YES];
}
}
}
-(void)viewWillAppear:(BOOL)animated{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
m_ImgVw_SelectedImage.image=img;
[popoverController dismissPopoverAnimated:YES];
[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
picker.delegate=nil;
}