错误 - 目标 C - '应用程序试图以模态方式呈现活动控制器 <splitViewDetailViewController:'
Posted
技术标签:
【中文标题】错误 - 目标 C - \'应用程序试图以模态方式呈现活动控制器 <splitViewDetailViewController:\'【英文标题】:Error - Objective C - 'Application tried to present modally an active controller <splitViewDetailViewController:'错误 - 目标 C - '应用程序试图以模态方式呈现活动控制器 <splitViewDetailViewController:' 【发布时间】:2012-06-13 09:56:03 【问题描述】:我想使用 UIImagePickerController 从 iPad 应用程序的照片库中加载照片。我正在使用以下代码行:
-(IBAction)photolibrarypressed:(id)sender
// / Create window
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSLog(@"hi");
// Set up the image picker controller and add it to the view
//imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//[window addSubview:imagePickerController.view];
//UIImagePickerController *picker= [[UIImagePickerController alloc]init];
//picker.delegate = self;
//picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[self presentModalViewController:picker animated:YES];
//[picker release];
imageView = [[UIImageView alloc] initWithFrame:[window bounds]];
// Set up the image view and add it to the view but make it hidden
[window addSubview:imageView];
imageView.hidden = YES;
[window makeKeyAndVisible];
但是,我收到以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <splitViewDetailViewController:
我无法理解。
该应用是SplitView 类型的,我同时使用了WebView 和ImageView。所以,当我点击按钮照片库时,我需要进入 ImageView(我想)。
有人可以帮我解决这个问题吗?我对目标 C 很陌生。谢谢。
【问题讨论】:
【参考方案1】:您已经获得了同时运行 iPhone 和 iPad 的代码。如果您使用的是 iPad,则应删除该行
[self presentModalViewController:picker animated:YES];
如果您使用的是 iPhone 或 iPod,则应删除该行
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
或者,如果您想在 iPad 和 iPhone 上运行您的应用程序,请使用 if 语句找出它在哪个设备上运行:
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
// Display in a popover for the iPad
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
else
// Display modally for the iPhone
[self presentModalViewController:picker animated:YES];
【讨论】:
以上是关于错误 - 目标 C - '应用程序试图以模态方式呈现活动控制器 <splitViewDetailViewController:'的主要内容,如果未能解决你的问题,请参考以下文章
应用程序不会以模态方式呈现,但崩溃与`应用程序试图以模态方式呈现活动控制器`
使用 UIAlertController 在 UIImagePicker 中“应用程序试图以模态方式呈现活动控制器”