ladessa-ios
ladessa-ios

Reputation: 283

Show ImagePicker in Popover - ipad

I'm trying to show my UIImagePicker in ipad landscape mode..

I have followed this example: https://github.com/guillermomuntaner/GMImagePicker

But I'm getting the following error:

<UIView: 0x7f8c9d158800; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x7f8c9d14f090>>'s window is not equal to <LoginRegisterViewController: 0x7f8c9ac51a70>'s view's window!

There's my code:

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        picker.modalPresentationStyle = UIModalPresentationPopover;

        UIPopoverPresentationController *popPC = picker.popoverPresentationController;
        popPC.permittedArrowDirections = UIPopoverArrowDirectionDown;
        popPC.sourceView = btnImagemPerfil;
        popPC.sourceRect = btnImagemPerfil.bounds;
        NSLog(@"%@", NSStringFromCGRect(btnImagemPerfil.bounds));
        [self showViewController:picker sender:sender];

and the log from btnImagemPerfil.bounds

{{0, 0}, {141, 141}}

Upvotes: 1

Views: 640

Answers (1)

ladessa-ios
ladessa-ios

Reputation: 283

Updating my code to:

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    appDelegate.window.rootViewController = self;

 UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        picker.modalPresentationStyle = UIModalPresentationPopover;

        UIPopoverPresentationController *popPC = picker.popoverPresentationController;
        popPC.permittedArrowDirections = UIPopoverArrowDirectionDown;
        popPC.sourceView = btnImagemPerfil;
        popPC.sourceRect = btnImagemPerfil.bounds;
        NSLog(@"%@", NSStringFromCGRect(btnImagemPerfil.bounds));
        [self showViewController:picker sender:sender];

it works for me

Upvotes: 2

Related Questions