2011-05-02 64 views
5

我有一個典型的UITableViewController視圖集。在所有視圖上都有一個按鈕,可以調出模型視圖。在該設置視圖是一個按鈕。我希望該按鈕可以解除模式視圖在UITableViewController的navigationController上實現popToRootViewController。如何從模態視圖中popToRootViewController?

駁回模式的看法很簡單:

[self dismissModalViewControllerAnimated:NO]; 

和工作正常。我試過這個彈出主UITableViewController:

[self.parentViewController.navigationController popToRootViewControllerAnimated:NO]; 

沒有任何反應。

我大概可以實現一個委託來實現這種情況,但是有相同的Settings按鈕的相當多的視圖控制器(具有更多的功能),所以首選查找不需要每個視圖中額外代碼的解決方案控制器。

非常感謝!

回答

1

找不到這樣的解決方案,所以我已經實現了一個協議/委託工作正常。只需:

[self.navigationController popToRootViewControllerAnimated:NO]; 

在委託調用中。

1

嘗試

[[[[UIApplication sharedApplication].keyWindow] rootViewController] popToRootViewController:YES]; 
+0

缺少navigationController(所以不會編譯),但即使添加爲[[[[UIApplication sharedApplication] .keyWindow rootViewController] navigationController] popToRootViewControllerAnimated:YES];它編譯但是什麼都不做。 – 2011-05-09 02:06:30

0

這對我的作品

[[self parentViewController] popToRootViewControllerAnimated:NO] 
6

退房由rdelmal(https://stackoverflow.com/a/16311935/1395563)的答案,這個工作對我來說就像魅力。我在模態視圖中使用此代碼。

[(UINavigationController *)self.presentingViewController popToRootViewController:NO]; 
[self dismissViewControllerAnimated:YES completion:nil]; 
1

在你的appdelegate文件

-(void)GotoRoot{ 
[self.navigationController popToRootViewControllerAnimated:YES];} 

現在把它在你的班組長烏爾註銷按鈕

[self dismissModalViewControllerAnimated:NO]; 
[(TestAppDelegate *)[[UIApplication sharedApplication] delegate]) GotoRoot]; 

請回復其結果添加的方法;