首先让我告诉你我正在尝试做什么:
- 当用户点击一个按钮时,我想呈现一个
UIPopoverController
和一个UINavigationController
作为它的contentViewController
(这是在 iPad 上) - 第一个插入
UINavigationController
的UIViewController
将是一个自定义 View Controller ,它有两个按钮:“拍照”和“从库中选择”。 - 触摸“拍照”按钮将
UIImagePickerController
上的setSourceType:UIImagePickerControllerSourceTypeCamera
并将其推送到UINavigationController
- 触摸“从库中选择”按钮将
UIImagePickerController
上的setSourceType:UIImagePickerControllerSourceTypePhotoLibrary
并将其推送到UINavigationController
我希望能够完成所有这些,并能够允许用户在 UINavigationController 允许的情况下向后导航。
问题是,由于 UIImagePickerController
也是一个 UINavigationController
,我无法将它推送到另一个 UINavigationController
中,如#3 和#4 中所述.
问题:
- 有没有办法让我使用
UIImagePickerController
并将自定义 View Controller 推送到相机/照片库 View Controller 之前? - 或者相反,有没有办法让我访问相机/照片库 View Controller 以将它们推送到不同的
UINavigationController
? - 或者还有另一种我完全想念的方式吗?
最佳答案
添加以下代码(详见 here )终于为我解决了这个问题。
使用 navigationController:willShowViewController:animated:
方法访问导航栏。
然后您可以使用此代码添加一个“取消”按钮。
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
}
关于objective-c - 如何允许用户选择 UIImagePickerController 的源类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9505207/