2012-08-08 49 views
1

注意: 在閱讀本問題之前,請注意,我已閱讀前面的問題,解釋有關蘋果執行UISplitViewController的不足之處以及我應該如何使用開放源代碼的「MGSplitViewController」,因爲在橫向模式下將主視圖控制器隱藏在分割視圖控制器上並不太容易。請記住,我僅限於在iOS 5.1中使用正常的UISplitViewController。UISplitViewController不會在橫向模式下隱藏masterViewController

現在到這樣的問題:

我有左側(主視圖)表視圖拆分視圖控制器和右側的詳細視圖控制器。我使用導航控制器來控制左側,這是一個轉換到另一個表視圖(「DataTableViewController」)的表視圖。爲了隱藏這個左側,我在詳細視圖控制器的導航工具欄上放置了一個「隱藏」按鈕。當按下隱藏按鈕,我改變我的「_hideMaster」屬性:

-(IBAction)hidePressed 
{ 
    _hideMaster = !_hideMaster; 
    // Must manually reset the delegate back to self in order to force call "shouldHideViewController" 
    self.splitViewController.delegate = nil; 
    self.spliteViewController.delegate = self; 

} 

,然後自動調用此方法在SplitViewController委託:

// This is called when I change the delegate from nil back to self. 
- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 
{ 
    return _hideMaster; 
} 

當我調試它,我可以看到,一切按計劃進行,屬性進入方法時具有正確的值splitViewController:shouldHideViewController:inOrientation:

唯一的問題是沒有任何反應。我最左邊的桌子視圖(DataTableViewController)不會消失。當我仔細觀察時,委託方法中的(UIViewController *)vc參數不是我想要隱藏的表視圖控制器,而是與此表視圖關聯的導航控制器。所以本質上它試圖隱藏導航控制器 - 這顯然不是我想要的...

我該如何使自動調用的委託方法(shouldHideViewController:)中的UIViewController參數調用與最上層的視圖控制器關聯與那個導航控制器? (畢竟,我想隱藏DataTableViewController

+0

真的希望能得到這個答案... – Bitwise 2012-08-08 03:18:50

回答

1

下面是我如何處理它。如果MasterViewController在返回時沒有實例化,可能需要更多工作才能使MasterViewController重新出現。

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.30f]; 
[[self.splitViewController.viewControllers lastObject] view].frame = self.splitViewController.view.frame; 
[UIView commitAnimations]; 
+0

不適用於我在iOS7上。 – Norbert 2013-09-25 08:28:34

相關問題