2013-02-04 105 views
0

我想以編程方式用SplitViewController替換當前視圖。這是我的代碼。UISPlitViewController彈出按鈕丟失

ProjectNavigationController *projectNavPanel = [[ProjectNavigationController alloc] init]; 
[projectNavPanel setProjectIndex:[indexPath row]]; 
[projectNavPanel setKuluId:[[[[[appDelegate userSettingsDictionary] objectForKey:@"Projects"] objectAtIndex:[indexPath row]] objectForKey:@"Kulu Id"] intValue]]; 

ProjectDetailController *projectDetailPanel = [[ProjectDetailController alloc] init]; 
[projectDetailPanel setProjectIndex:[indexPath row]]; 
ProjectSplitViewController *splitRootController = [[ProjectSplitViewController alloc] init]; 

[splitRootController setViewControllers:[NSArray arrayWithObjects:projectNavPanel, projectDetailPanel, nil]]; 

[[self view] removeFromSuperview]; 
[[appDelegate window] setRootViewController:splitRootController]; 

這幾乎工作正常,只有一個例外。當加載拆分視圖控制器並處於縱向模式時,導航視圖隱藏 - 如預期的那樣 - 但詳細視圖沒有工具欄,其中有一個按鈕用於在彈出視圖中顯示導航。從我的研究中,我明白這是默認行爲。我錯過了什麼嗎? detailViewController中的內容很少,所以我沒有在這裏包含代碼,但是如果它有幫助,請告訴我。

+0

有沒有人有任何想法? – Typhoon101

回答

1

代碼中缺少一些內容;

首先,要讓導航欄添加按鈕,您必須在UISplitViewControllerProjectDetailController之間有UINavigationController

其次,你必須設置一個UISplitViewControllerDelegate和使用委託方法來添加按鈕:

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc 
{ 
    [[projectDetailPanel navigationItem] setLeftBarButtonItem:barButtonItem animated:YES]; 
} 

- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem 
{ 
    [[projectDetailPanel navigationItem] setLeftBarButtonItem:nil animated:YES]; 
} 

第三,不要忘記將標題設置爲您ProjectNavigationController,或者手動設置一個標題您剛剛實施的splitViewController:willHideViewController:withBarButtonItem:forPopoverController方法中的barButtonItem