我知道 iPad 上的图像选择器需要是一个弹出框,我一直在尝试,但是当我点击调用弹出框的按钮时它不会工作并崩溃。
-(IBAction)addPhoto:(id)sender{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
popover=[[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:((UIButton *)sender).frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
// Delete any existing image.
NSManagedObject *oldImage = imageClass.image;
if (oldImage != nil) {
[imageClass.managedObjectContext deleteObject:oldImage];
}
// Create an image object for the new image.
NSManagedObject *myImage = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:imageClass.managedObjectContext];
imageClass.image = myImage;
// Set the image for the image managed object.
[image setValue:selectedImage forKey:@"image"];
[self dismissViewControllerAnimated:YES completion:nil];
}