0

I am using this code in my button action function:

picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
picker.wantsFullScreenLayout = YES;
[self presentViewController:picker animated:YES completion:nil];

I am implementing the delegate also. UIImagePickerControllerDelegate

But it gets crashed at [self presentViewController:picker animated:YES completion:nil];

Can som one help me out on what I am doing wrong?

NiKKi
  • 3,296
  • 3
  • 29
  • 39
  • Can you post the stack trace? you're probably missing something. Add an Exception Breakpoint if you haven't done so already – Ismael Dec 27 '12 at 14:31
  • use this [self presentViewController:picker animated:YES]; instead of [self presentViewController:picker animated:YES completion:nil]; – Talha Dec 27 '12 at 14:32
  • are you using this on ipad? – prasad Dec 27 '12 at 14:33
  • @prasad - I am using iPod. – NiKKi Dec 27 '12 at 14:54
  • @Talha - Even after using [self presentViewController:picker animated:YES]; its the same. – NiKKi Dec 27 '12 at 14:54
  • can you please post the stack trace of the crash? – Talha Dec 27 '12 at 14:55
  • http://stackoverflow.com/questions/10147625/unable-to-get-presentviewcontroller-to-work if you check this link according to this if we are presenting viewcontroller from viewDidLoad method of a rootViewController this crash occurs, but still it will be better if you provide crash details so more peoples can help you. – prasad Dec 27 '12 at 15:04
  • 2
    if you are app supports only Landscape.. then this link could solve your problem http://stackoverflow.com/a/13763016/1059705 – Bala Dec 27 '12 at 15:37
  • did you add `UIImagePickerControllerDelegate,UINavigationControllerDelegate` in `.h`? – Ankur Arya Dec 28 '12 at 06:36
  • use like this, `[self.navigationController presentModalViewController:picker animated:YES ];` – Venk Dec 28 '12 at 07:01
  • @Bala - Thanks. Your comment helped me, although the link did not helped.. :) – NiKKi Dec 28 '12 at 07:09

1 Answers1

0

This is for IOS 6. These delegate methods are supported only in IOS 6. I got the answer to my own question. My application was developed for landscape mode only. So the imagePickerView was not able to present itself as its default orientation is landscape. So I made my application supported for landscape and portrait mode. In the app delegate I used the method,

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    return UIInterfaceOrientationMaskAll;
else  /* iphone */
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

And in the rootViewController I used the following delegates to force the viewController to be in landscape mode and remain in landscape mode.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    return YES;
else
    return NO;
}
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;

}

And it worked.

NiKKi
  • 3,296
  • 3
  • 29
  • 39