2011-02-14 99 views
2

我有一個MainWindowController,我想關閉「touch inside」按鈕事件並打開一個新的UIView。 我使用的代碼是這樣的:如何關閉UIVIewController?

NewViewController *controller = [[NewViewController alloc] 
initWithNibName:@"NewView" bundle:nil]; 
controller.delegate = self; 
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:controller animated:YES]; 
[controller release]; 

但這種方式的MainWindowController不要關閉它的自我。

+0

presentModalViewController - 基本上將上述現有的新視角,那麼你的意思是想要關閉現有的? – 2011-02-14 09:26:37

回答

0

您應該使用UINavigationController來管理UIViewControllers的推送和彈出。 在UINavigationController中你應該定義一個根視圖控制器,子視圖控制器就像圖層一樣添加在它上面。

你可以有一個根,並添加一個孩子。當你按下按鈕時,彈出小孩並讓其他小孩按下。

的行動將是這樣的:

根推child1(根由child1覆蓋)

根彈出child1(根可見)

根推的child2(根由的child2覆蓋)

這裏是一個link到UINavigationController文檔。

如果你想從UIViewController中移除UIView,那麼你不需要UINavigation控制器。您可以在viewController中創建2個UIView,並在按下按鈕時交換它們。

1)創建一個UIView舉行交換意見(容器)

2)構造要之間要交換UIViews。把它們放在一個數組中。

3)把你的按鈕掛到一個動作方法。這個方法應該找出需要顯示的視圖的索引,刪除所有容器的子視圖,將子視圖[viewsArray objectAtIndex:nextViewIndex]添加到容器。

1

在選擇/方法,你的呼籲的「潤色內部」事件,請嘗試使用

[self dismissViewControllerAnimated:YES completion:{ 
//Optional, but could be used to do something magical, once controller has been dismissed 
}];