2015-12-30 96 views
0

我得到一個錯誤exc_bad_access,當我使用dismissviewcontrolleranimated當我使用dismissviewcontrolleranimated,我得到EXC_BAD_ACCESS

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"); 
}]; 

感謝您的幫助。

+0

你在使用故事板嗎? –

+0

不,我沒有使用故事板,只有xib –

回答

0

UINavigationController有Push和Pull轉換,並且您試圖將Modal Transition應用於它。

0

當前視圖控制器通過「根視圖控制器」而不是UINavigationController呈現。 你應該從父VC或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的正確方法。

相關問題