Invalid UIImagePickerController delegate method (set of delegates for itself)
I have a problem:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {}
is only called with the camera, not when I try to select an image while viewing the user's photos.
here is my initialization code for the UIImagePicker delegate:
-(void)viewDidLoad{
[self initImagePicker];
}
-(void)initImagePicker{
DLog(@"");
self.imagePickerController.delegate = self;
}
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,CGRectGetHeight(overlayViewFrame)-15.0,CGRectGetWidth(overlayViewFrame),15.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
[self.view bringSubviewToFront:self.view];
}
}
}
then in my root class which is the delegate of the UIImagePicker class which is the delegate of the UIImagePicker:
#pragma mark -
#pragma mark Toolbar Actions
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// camera is not on this device, don't show the camera button
NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:self.myToolbar.items.count];
[toolbarItems addObjectsFromArray:self.myToolbar.items];
[toolbarItems removeObjectAtIndex:2];
[self.myToolbar setItems:toolbarItems animated:NO];
}
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
self.overlayViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"OverlayViewController"];
self.overlayViewController.delegate = self;
self.overlayViewController.imagePickerController = [[UIImagePickerController alloc] init];
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}
I know this is a lot of code for an SO question, but for people who have experience implementing this class, what am I doing wrong?
For me this line is strange:
self.overlayViewController.imagePickerController = [[UIImagePickerController alloc] init];
I've never allocated or initialized a property outside of the owner before. This is problem?
+3
source to share
3 answers
Set UIImagePickerDelegate and UINavigationControllerDelegate in .h file using @interface.
As if
@interface class : UIView <UIImagePickerDelegate , UINavigationControllerDelegate>
The self delegate is also assigned using the UIImagePickerController object,
imgPickerController.delegate = self;
Hope this helps too.
+1
source to share