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


所以我有一个 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."];
    }
}

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

谢谢

利亚姆


5014
2018-05-05 14:41


起源



答案:


啊......经过一段时间的休息,我发现了这个: 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 

}

11
2018-05-05 15:17



奇迹般有效。 - Jivko Petiov


答案:


啊......经过一段时间的休息,我发现了这个: 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 

}

11
2018-05-05 15:17



奇迹般有效。 - Jivko Petiov