我無法通過在詳細視圖中按左按鈕來顯示主視圖(即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];
}
另外一個觀察結果是,我可以通過使用滑動手勢滑出主視圖。只是左邊的按鈕不起作用。 – user1881383
問題解決了。我用UINavigationController替換了UIToolbar,並且現在可以通過單擊左鍵來顯示主視圖。 – user1881383