2012-12-14 100 views
0

我無法通過在詳細視圖中按左按鈕來顯示主視圖(即UITabBarController)。以下代碼是我如何實現UISplitViewControllerDelegate以設置左側按鈕。UISplitViewController的詳細視圖中的左按鈕無法顯示UITabBarController(即主視圖)

我正在使用iOS 6和Xcode 4.5。

#pragma mark - UISplitViewControllerDelegate 
#warning "incomplete implementation" 

- (BOOL)splitViewController:(UISplitViewController *)svc 
    shouldHideViewController:(UIViewController *)vc 
       inOrientation:(UIInterfaceOrientation)orientation { 
    return UIInterfaceOrientationIsPortrait(orientation) ? YES : NO; 
} 

- (void)splitViewController:(UISplitViewController *)svc 
    willHideViewController:(UIViewController *)aViewController 
      withBarButtonItem:(UIBarButtonItem *)barButtonItem 
     forPopoverController:(UIPopoverController *)pc { 
    barButtonItem.title = aViewController.title; 

    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy]; 
    [toolbarItems insertObject:barButtonItem atIndex:0]; 
    self.toolbar.items = [toolbarItems copy]; 
} 

- (void)splitViewController:(UISplitViewController *)svc 
    willShowViewController:(UIViewController *)aViewController 
    invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { 
    NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy]; 
    [toolbarItems removeObject:barButtonItem]; 
    self.toolbar.items = [toolbarItems copy]; 
} 
+0

另外一個觀察結果是,我可以通過使用滑動手勢滑出主視圖。只是左邊的按鈕不起作用。 – user1881383

+0

問題解決了。我用UINavigationController替換了UIToolbar,並且現在可以通過單擊左鍵來顯示主視圖。 – user1881383

回答

0

問題解決了。我用UINavigationController替換了UIToolbar,並且現在可以通過單擊左鍵來顯示主視圖。

+0

我有同樣的問題。我應該打什麼方法? http://stackoverflow.com/questions/14334939/uisplitviewcontroller-how-to-present-master-view-in-the-detail-view-by-button – zono

+0

你的情況和我的一樣嗎?如果是的話,我沒有編輯任何代碼來使其工作。唯一的變化是用UINavigationController替換UIToolbar。 – user1881383

0

爲了將來的參考,通過設置分割視圖控制器委託和實現這兩個方法,你應該準備好去。

- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)button 
    { 
     //remove button from navigation bar in detail navigation controller 
     ((UINavigationController*)[svc.viewControllers objectAtIndex:1]).topViewController.navigationItem.leftBarButtonItem = nil; 
    } 

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc{ 

     //add button to navigation bar in detail navigation controller 
     barButtonItem.title = @"Navigation"; 
     ((UINavigationController*)[svc.viewControllers objectAtIndex:1]).topViewController.navigationItem.leftBarButtonItem = barButtonItem; 

    } 

barButtonItem的實例爲您處理所有的切換過程。

相關問題