0

I need to know how to open the gallery in iPhone SDK. I believe my code is correct, but I'm still getting an exception.

This is my code:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        imgpkrController.delegate = self;
        imgpkrController.allowsEditing = YES;
        imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];

        [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];}

By using this code the am getting the exception:

UIApplicationInvalidInterfaceOrientation', reason:
  preferredInterfaceOrientationForPresentation must return a supported interface orientation!

So I tried this code:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        UIInterfaceOrientation interface = [[UIApplication sharedApplication] statusBarOrientation];
        if(interface == UIDeviceOrientationPortrait)
        {
            imgpkrController.delegate = self;
            imgpkrController.allowsEditing = YES;
            imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];

            [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];

        }else if (interface ==UIDeviceOrientationLandscapeLeft || interface ==UIDeviceOrientationLandscapeRight)
        {
            imgpkrController.delegate = self;
            imgpkrController.allowsEditing = YES;
            imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];
            [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];}}

But this gives the same exception. Can anybody help me out with this?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138

1 Answers1

0

I don't think any thing is wrong with the earlier Code you were using. Keep using that code for this purpose. I think there is a problem with the code in UIInterfaceOrientation. You can try this Go to Target-> Summery -> and then try to handle the orientations from there.

If that does not help then you need to study regarding the UIInterfaceOrientation in the following links

http://www.scott-sherwood.com/ios-6-uiapplicationinvalidinterfaceorientation-exception/

  • Ankit i Tried to do the the Way You Tell but cudnt able to succeed. Is There anyone Who can Help me out from this Problem. – Abhishek Rajput Jun 06 '13 at 09:28
  • imgpkrController should have already been defined as an view controller why you add imgpkrController in present model view controller like (UIViewController *)imgpkrController. –  Jun 06 '13 at 10:04
  • Because this is the only way that i know. if there are other way to do this then please share it with me. This code is working perfectly on other project but not on this project. – Abhishek Rajput Jun 06 '13 at 10:20