2012-11-07 35 views
0

這是工作非常精細:setViewControllers當動畫使用:NO

[(UINavigationController*)viewController setViewControllers:[NSArray arrayWithObject:cvc] animated:YES]; 

但是這會導致我的應用程序崩潰:

[(UINavigationController*)viewController setViewControllers:[NSArray arrayWithObject:cvc] animated:NO]; 

我已經在其他使用同一行部分與不同的viewController與動畫:NO,它工作正常。我錯過了什麼,或者它是一個錯誤?

+0

你是否使用autorelease爲cvc分配內存? – rishi

+0

只是檢查您的cvc數據,然後傳遞到導航控制器 – Rajneesh071

+0

不autorelease。但是,我的項目是ARC啓用。這是cvc的代碼行。 CouponDetailViewController * cvc = [self.storyboard instantiateViewControllerWithIdentifier:@「CouponView」]; – CRDave

回答

0

如果您要設置您的視圖控制器RootViewController的那麼做到這一點

yourNavigationController=[[UINavigationController alloc]initWithRootViewController:cvc]; 

,然後當你想去newViewController然後用pushViewController

[self.navigationController pushViewController:yourViewObject animated:YES]; 
+0

我的代碼在其他地方工作的很好。我已經在TabBarViewController中使用它。只有在一個地方它給出了錯誤,並且也只有當我用動畫NO。它與動畫YES正常工作。 – CRDave

+0

給我示例代碼..我會檢查你的代碼。 – Rajneesh071

0

蘋果公司已經給這個函數的文檔只有動畫設置爲YES。

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); //如果animated爲YES,則根據新的頂部視圖控制器是否先前位於堆棧中來模擬push或pop。

我認爲當您將動畫設置爲'否'時,新的頂層NavigationController尚未初始化並正確加載,直到動畫完成。

相關問題