UIPopoverController中的UIImagePickerController在iOS7上不显示“取消”按钮 [英] UIImagePickerController inside UIPopoverController doesn't show Cancel button on iOS7
问题描述
我在UIPopoverController中使用UIImagePickerController来从相册中选择图像。当我在运行iOS 8的设备上启动应用程序时,弹出窗口右上角的取消按钮通常如下所示:
I'm using UIImagePickerController inside a UIPopoverController to select image just from photo albums. When I launch app on device running iOS 8, the Cancel button on the top right of the pop over appeared normally like this:
但是当我在运行iOS 7的设备上启动应用程序时,取消按钮消失:
But when I launch the app on device running iOS 7, the Cancel button disappeared:
我用来显示选择器的代码:
The code I used to show the picker:
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
[pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
pickerController.delegate = self;
_popOver = [[UIPopoverController alloc] initWithContentViewController:pickerController];
_popOver.delegate = self;
pickerController.navigationBar.tintColor = [UIColor redColor];//Cancel button text color
[pickerController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];// title color
if (isImage) {
[pickerController setMediaTypes:@[(NSString*)kUTTypeImage]];
} else
[pickerController setMediaTypes:@[(NSString*)kUTTypeMovie]];
[_popOver presentPopoverFromRect:CGRectMake(1024/2, 768/2, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
如何在iOS7上显示取消按钮?我的应用程序设计不允许用户通过点击弹出窗口视图外的任何位置来关闭弹出框。
What can I do to show that Cancel button on iOS7? My app design doesn't allow user to dismiss the popover by tapping anywhere outside the popover view.
谢谢。
推荐答案
@JozoL编写下面这段代码
@JozoL Write the Below Code this works
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *pickerNavBarTopItem;
// add done button to right side of nav bar
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
style:UIBarButtonItemStylePlain
target:self
action:@selector(doSomething)];
UINavigationBar *bar = navigationController.navigationBar;
[bar setHidden:NO];
pickerNavBarTopItem = bar.topItem;
pickerNavBarTopItem.rightBarButtonItem = doneButton;
}
-(void)doSomething{
}
这篇关于UIPopoverController中的UIImagePickerController在iOS7上不显示“取消”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!