xcode “应用程序试图以模态方式呈现活动控制器”iOS5 中的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7920098/
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
“Application tried to present modally an active controller” Error in iOS5
提问by GuybrushThreepwood
I have an error which is causing my app to crash under iOS5 only on the iPad.
我有一个错误,导致我的应用程序在 iOS5 下仅在 iPad 上崩溃。
The below code is called when the user taps on an item in a uibarbutton item :
当用户点击 uibarbutton 项目中的项目时,将调用以下代码:
- (void)optionSelected:(NSString *)option {
[self.optionPickerPopover dismissPopoverAnimated:YES];
if ([option compare:@"Map View"] == NSOrderedSame) {
NSLog(@"Map View");
MapView * map = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:map];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self action:@selector(removeCurrent)];
map.navigationItem.rightBarButtonItem = rightButton;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[map release];
[rightButton release];
[split presentModalViewController:map animated:YES];
}
Can anyone suggest why this occurring in iOS5 ?
谁能建议为什么会在 iOS5 中发生这种情况?
回答by Robin Summerhill
You are getting this error because you are attempting to display the 'map' view controller twice. The first time is as the root view controller of 'navigationController' and the second time is via [split presentModalViewController:map animated:YES]
.
您收到此错误是因为您试图两次显示“地图”视图控制器。第一次是作为 'navigationController' 的根视图控制器,第二次是 via [split presentModalViewController:map animated:YES]
。
iOS 5 is being a bit more picky than iOS 4 when you try to do strange things with view controllers. Trying to show the same controller twice is a design problem - you need to work out what you are really trying to do and fix it.
当你尝试用视图控制器做奇怪的事情时,iOS 5 比 iOS 4 更挑剔。试图两次显示同一个控制器是一个设计问题——你需要弄清楚你真正想要做什么并修复它。
(Also, calling a map view controller 'MapView' rather than 'MapViewController' is really confusing)
(此外,调用地图视图控制器“MapView”而不是“MapViewController”确实令人困惑)
回答by whyoz
This error will also occur if you don't follow these guidelines: Creating Custom Content View Controllers
如果您不遵循以下准则,也会发生此错误:创建自定义内容视图控制器
Basically, you need to call:
基本上,您需要调用:
[yourVC removeFromParentViewController];
[你的VC removeFromParentViewController];
if you've
如果你有
[parentVC addChildViewController:yourVC];
[parentVC addChildViewController:yourVC];
This error may often be paired with something about "UIViewControllerHierarchyInconsistency"
此错误通常与“UIViewControllerHierarchyInconsistency”有关