我有一个错误导致我的应用仅在iPad上的iOS5下崩溃。
当用户点击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];
}
有谁能说明为什么会出现在iOS5中?
答案 0 :(得分:8)
您收到此错误是因为您试图显示地图'查看控制器两次。第一次是作为' navigationController'的根视图控制器。第二次是通过[split presentModalViewController:map animated:YES]
。
当您尝试使用视图控制器进行奇怪的操作时,iOS 5比iOS 4更挑剔。试图两次显示相同的控制器是一个设计问题 - 你需要找出你真正想做的事情并修复它。
(另外,调用地图视图控制器' MapView'而不是' MapViewController'真的很混乱)
答案 1 :(得分:3)
如果您不遵循以下准则,也会出现此错误:Creating Custom Content View Controllers
基本上,您需要致电:
[yourVC removeFromParentViewController];
如果你
[parentVC addChildViewController:yourVC];
此错误通常可能与“UIViewControllerHierarchyInconsistency”
的内容配对