xcode 错误 - 目标 C - '应用程序试图以模态方式呈现一个活动控制器 <splitViewDetailViewController:'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11012438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:35:37  来源:igfitidea点击:

Error - Objective C - 'Application tried to present modally an active controller <splitViewDetailViewController:'

iphoneobjective-ciosxcodeipad

提问by

I want to use UIImagePickerController to load photos from the photolibrary of the IPad Application. I am using the following line of code :

我想使用 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];     

}

But however, I am getting the following error :

但是,我收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <splitViewDetailViewController: 

I am unable to understand it.

我无法理解。

The app is of SplitView Type and I have used WebView and ImageView simultaneously. So,when I click on the button photolibrary I need to go into the ImageView(I suppose).

该应用程序是 SplitView 类型,我同时使用了 WebView 和 ImageView。所以,当我点击按钮 photolibrary 时,我需要进入 ImageView(我想)。

Can someone please help me sort out the issue ?? I am pretty new to objective C. Thanks.

有人可以帮我解决问题吗??我对目标 C 很陌生。谢谢。

采纳答案by jjv360

You've got the code for the iPhone and iPad running at the same time. If you're on an iPad, you should remove the line

您已经同时运行了 iPhone 和 iPad 的代码。如果您使用的是 iPad,则应删除该行

[self presentModalViewController:picker animated:YES];

and if you're on an iPhone or iPod you should remove the line

如果您使用的是 iPhone 或 iPod,则应删除该行

[popoverController presentPopoverFromBarButtonItem:sender  permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Alternatively if you want to run your app on both iPad and iPhone, use an if statement to find out which device it's running on:

或者,如果您想在 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];

}