2012-03-01 68 views
2

我是IOS新手,提前對不起,如果我問一個愚蠢的問題。殺死查看並返回rootViewController

我使用的UITabBarController和navigationController控制視圖。

在我的最後一個視圖中,當按下按鈕時,我想要一個按鈕,視圖將返回到由MainWindow.xib文件設置的rootViewController,並終止在應用程序背景中運行的任何進程。

這是我在過去的視圖代碼之前,我想回RootViewController的:

-(IBAction)doneButtonPressed:(id)sender{ 


    JourneyIndexViewController *journeyIndexVC = [[JourneyIndexViewController alloc]  initWithNibName:@"JourneyIndexViewController" bundle:nil]; 

    [journeyIndexVC setDistanceLabelValue:self.distanceLabelValue]; 

    [self.navigationController pushViewController:journeyIndexVC animated:YES]; 
    [journeyIndexVC release]; 
    [self dismissModalViewControllerAnimated:YES]; 

    } 

JourneyIndexViewController的是,我在MainWindow.xib中設置RootViewController的。

非常感謝您的提前支持。

回答

0

試試這個。這應該會讓你回到前一個視圖控制器。

[self.navigationController popViewControllerAnimated:NO]; 

希望這有助於

+0

感謝@ tonio.mg,我嘗試過,但它只是回視圖之前。 – 2012-03-01 15:00:31

+0

所以你就像在第三個視圖中,你想回到第一個視圖? – 2012-03-01 15:02:08

+0

是的,我想殺了任何東西,然後回到第一個。 – 2012-03-01 15:04:51

0

我在這裏做了一些假設,但如果JourneyIndexRootViewController是你的RootViewController的和IB創建(在筆尖),你不需要推何時重新克里特它按鈕。這聽起來像你只需要刪除你在rootViewController上添加的UINavigationController。

+0

是的,你是對的。你能告訴我如何以及在哪裏編碼?謝謝。 – 2012-03-01 15:05:59

+0

要做到這一點,我可能會創建一個協議,您的JourneyIndexRootViewController實現了從上一個視圖中調用的委託。你會實現一個簡單的方法,在其中刪除UINavigationController視圖。 – 2012-03-01 15:14:46