如果我在 iOS 中使用 instantiateViewControllerWithIdentifier 显示视图控制器,我无法离开视图控制器而不会崩溃。视图加载正常并执行其任务,但是当我尝试通过按下按钮离开它时,应用程序崩溃。这是因为某些错误的状态还是我犯了另一个错误?
代码:
- (IBAction)push:(id)sender {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
NSLog(@"story: %@",mainStoryboard.description);
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ListViewController *controller = (ListViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"ListId"];
appDelegate.window.rootViewController = controller;
}