2012-07-07 27 views
1

我從here得到了這段代碼,它可以按我的需要完美工作。但問題是當我想彈出視圖控制器並返回到主屏幕時。當我使用「彈出」後無法推送viewController

[self.navigationController popViewControllerAnimated:YES];
時,它不會無所事事。但是當我使用相同的代碼時,它可以工作,但不像我想要的那樣,從「從左到右」。

這是代碼,我必須做些什麼才能讓它在同一個方向上彈出視圖控制器?我明白,它把viewController放在我正在做的那個之前,而不是流行它,但現在我該如何推?當我試圖推動我得到錯誤。

NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers]; 
    [vcs insertObject:levelsView atIndex:[vcs count]-1]; 
    [self.navigationController setViewControllers:vcs animated:NO]; 
    [self.navigationController popViewControllerAnimated:YES]; 

回答

0

你應該使用

[self.navigationController popToRootViewControllerAnimated:YES]; 
+0

它不工作..我真的沒有任何線索爲什麼。另外,我只想到前面的視圖,而不是根視圖。 – 2012-07-08 11:44:44

+0

你是否得到它的工作? – alandalusi 2012-08-18 19:40:13

0

首先深深調試您的代碼段回到主屏幕。檢查你的數組vcs,對象是否正在插入?如果是的話,檢查self.navigationController不是零..如果沒有,然後詳細說明你的代碼。如果你不想公開你的代碼嘗試替代動畫。

嘗試使用CATransition動畫效果。

CATransition * trans = [CATransition animation]; 
trans.type = kCATransitionPush; 
trans.subtype = kCATransitionFromLeft; 
trans.duration = 0.22;