gpt4 book ai didi

ios - UIPopoverController 内的 UIImagePickerController 在 iOS7 上不显示取消按钮

转载 作者:行者123 更新时间:2023-12-01 18:56:09 27 4
gpt4 key购买 nike

我在 UIPopoverController 中使用 UIImagePickerController 仅从相册中选择图像。当我在运行 iOS 8 的设备上启动应用程序时,弹出窗口右上角的取消按钮通常如下所示:

enter image description here

但是当我在运行 iOS 7 的设备上启动应用程序时,取消按钮消失了:
enter image description here

我用来显示选择器的代码:

    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 上显示取消按钮?我的应用程序设计不允许用户通过点击弹出框 View 之外的任何位置来关闭弹出框。

谢谢你。

最佳答案

@JozoL 编写下面的代码这行得通

- (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{

}

关于ios - UIPopoverController 内的 UIImagePickerController 在 iOS7 上不显示取消按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26922471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com