2012-06-28 44 views
5

私のアプリケーションには10のviewControllerがあります。私は、各viewControllerをクリックしたNEXTボタンのNavigationControllerのpushViewControllerメソッドを使用して、これらのviewControllerをすべてプッシュしました。PushViewControllerを解除するにはどうすればいいですか?

私はそのためにコードを使用しました。

[self.navigationController pushViewController:someView animated:YES]; 

ここで、私は10番目の子(viewController)からrootViewControllerに戻りたいと思います。

どうすればいいですか?

助けてください。

ありがとうございます。あなたは、特定のビューの [self.navigationController popViewControllerAnimated:YES] を使用することができます

答えて

16

あなたは私のlife..thanksを保存

[self.navigationController popToRootViewControllerAnimated:YES]; 
+0

..使用するようにしてください。..バック最後の画面での使用に行くためにこの

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Use the desired index instead of 1 here 

をお試しください –

1

..

10

使用このコード:

[self.navigationController popToRootViewControllerAnimated:YES]; 
1
NSInteger index = 0; 
for (UIViewController *view in self.navigationController.viewControllers) { 
if([view.nibName isEqualToString:@"RootViewController"])//put any `XIB name` where u want to navigate 
    break; 
index = index + 1; 
} 
[[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES]; 
1

は、前の画面に戻る(ビューコントローラスタックの最後の要素)、ビューコントローラをポップアップします。

[self.navigationController popViewControllerAnimated:YES]; 
9

ちょうどこの

[self.navigationController popViewControllerAnimated:YES] 
関連する問題