在UIPopoverController中显示UIImagePickerController与现有的UINavigationController(添加后退按钮)

lia*_*ols 11 objective-c uikit uiimagepickercontroller uipopovercontroller ios

所以我有一个UIPopoverController房子UINavigationController,我有我的地方UITableViewController但是我的一个选择UITableView是去选择一个图像与UIImagePickerController...现在在iPhone上,我可以简单地使用presentModalViewController:animated:但是从UIPopoverController内调用,导致崩溃,所以这不可能...

我也知道UIImagePickerController它自己的需求UINavigationController所以我不能只推动pushViewController:animated:......

所以我想出如果我保留了UIPopoverController我创建的链接,那么我可以setContentViewController:animated:用来切换到UIImagePickerController的viewController ......

但是,我现在坚持让用户回到之前的方式,UINavigationController因为我需要能够添加一个取消按钮UIImagePickerController但是当我尝试这样做时,取消按钮将不会被添加...

继承我正在使用的代码

-(void)doPhotoalbums {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        [imagePicker setDelegate:self];
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [imagePicker setContentSizeForViewInPopover:CGSizeMake(320, 480)];

        UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil];
        [imagePicker.navigationItem setLeftBarButtonItem:cancel];

        //[self presentModalViewController:imagePicker animated:YES];
        [[self parentPopoverController] setContentViewController:imagePicker animated:YES];

    } else {
        [UIAlertView showMessage:@"This device does not have any photo albums."];
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我的问题是..有谁知道我怎么能解决这个问题?通过添加取消/返回按钮,我可以挂钩,以使导航控制器切换回来或另一种方式来呈现这一点(我想避免在两个UIPopoverControllers之间切换,但我不知道我还能做什么..

谢谢

利亚姆

lia*_*ols 11

啊......经过一段时间的休息后我发现了这个:https://discussions.apple.com/thread/1710435?start = 0&tstart = 0

使用UINavigationControllerDelegate可以使用该navigationController:willShowViewController:animated:方法访问navigationBar ..然后使用一些代码(如下),您可以添加一个按钮.

if ([navigationController isKindOfClass:[UIImagePickerController class]]) {

    UINavigationBar *bar = navigationController.navigationBar;
    UINavigationItem *top = bar.topItem;

    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(imagePickerControllerDidCancel:)];
    [top setLeftBarButtonItem:cancel];

} else { 

    //do non imagePickerController things 

}
Run Code Online (Sandbox Code Playgroud)