"应用程序尝试以模态方式呈现活动控制器"iOS5中的错误

Guy*_*ood 3 iphone sdk xcode ipad ios5

我有一个错误导致我的应用程序仅在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];
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议为什么会出现在iOS5中?

Rob*_*ill 7

您收到此错误是因为您尝试两次显示"地图"视图控制器.第一次是'navigationController'的根视图控制器,第二次是via [split presentModalViewController:map animated:YES].

当你尝试用视图控制器做一些奇怪的事情时,iOS 5比iOS 4更挑剔.试图两次显示相同的控制器是一个设计问题 - 你需要找出你真正想做的事情并修复它.

(另外,调用地图视图控制器'MapView'而不是'MapViewController'真的很混乱)