gpt4 book ai didi

ios - 在 iPad 上从 ActionSheet 显示 ImagePickerController

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:46 25 4
gpt4 key购买 nike

背景:在 iPad 上,我有一个按钮,点击该按钮会显示一个 UIActionSheet。此操作表有 2 个选项,相机和画廊。点击相机,拉起相机,一切正常。点击图库时,假设显示一个带有用户照片的弹出窗口。

问题:在 iPad 上,UIActionSheet 就像一个弹出窗口。呈现时,无法看到另一个弹出窗口。错误:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到。”

我的代码:
设置操作表

- (void)imageButtonTapped:(UIButton *)sender
{
if (_commentObject.image){
_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove" otherButtonTitles:nil];
_actionSheet.tag = ACTION_IMAGE_REVIEW_TAG;
}else{
_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Image Source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Gallery", nil];
_actionSheet.tag = ACTION_IMAGE_SOURCE_TAG;
}

if (_isPad) {
[_actionSheet showFromRect:_imageButton.frame inView:_scrollViewContent animated:YES];
}else{
[_actionSheet showInView:self.view];
}
}

代表

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (actionSheet.tag) {
case ACTION_IMAGE_SOURCE_TAG:
switch (buttonIndex) {
case 0:
[self pickImage:YES];
break;
case 1:
[self pickImage:NO];
break;
default:
break;
}
break;
}

执行

- (void)pickImage:(BOOL)fromCamera
{
if (fromCamera) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPickerController.delegate = self;
[self presentViewController:cameraPickerController animated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera Unavailable" message:@"Your Device does not support Cameras" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}else{
UIImagePickerController *galleryPickerController = [[UIImagePickerController alloc] init];
galleryPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
galleryPickerController.delegate = self;

if (_isPad) {
if ([_actionSheet isVisible]) {
[_actionSheet removeFromSuperview];
UIPopoverController *imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:galleryPickerController];
[imagePickerPopover presentPopoverFromRect:_imageButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}else{
[self presentViewController:galleryPickerController animated:YES completion:nil];
}
}
}

问题:我尝试从 View 中删除操作表,并尝试在执行 pickImage 之前将其关闭。这些都不起作用。我如何展示画廊?

最佳答案

您的问题:错误:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到。

在您的 .h 文件类中创建 UIPopoverController 的对象。确保您的 UIPopoverController 的 @property 是强的而不是弱的。

检查这个

UIPopoverController: dealloc reached while popover is still visible

UIPopovercontroller dealloc reached while popover is still visible

关于ios - 在 iPad 上从 ActionSheet 显示 ImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18188922/

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