当我使用dismissviewcontrolleranimated时,我得到了exc_bad_access

时间:2015-12-30 07:31:32

标签: ios

当我使用exc_bad_access

时,我收到了错误dismissviewcontrolleranimated

presentViewController代码为:

TestViewController *testViewController=[[TestViewController alloc] init];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:testViewController];
[self presentViewController:nav animated:YES completion:^{
    NSLog(@"presentViewController is finish");
}];

但是,当我删除UINavigationController时,错误就会消失。

像这样:

TestViewController *testViewController=[[TestViewController alloc] init];
[self presentViewController:testViewController animated:YES completion:^{
    NSLog(@"presentViewController is finish");
}];

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

UINavigationController有推送和拉动转换,您正尝试将Modal Transition应用于它。

答案 1 :(得分:0)

现在的视图控制器通过“根视图控制器”呈现,而不是UINavigationController。 您应该像这样

从Parent VC或Base VC中展示您的VC
TestViewController *testViewController=[self.storyboard instantiateViewControllerWithIdentifier:@"storyboardIDofViewController"];//set the storyboard ID of the TestViewController in your storyboard by selecting attribute inspector after selecting the view controller.
    [self presentViewController:testViewController animated:YES completion:^{
    NSLog(@"presentViewController is finish");
}];

这是从另一个VC呈现VC的正确方法。