我正在尝试在详细视图的导航栏中添加一个按钮,以在纵向模式下显示主视图,但该按钮未显示。任何人都可以提供帮助或提供建议吗?
这是我在详细视图中尝试执行的操作:
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
mainMenu = barButtonItem;
[mainMenu setTitle:@"Menu"];
[[self navigationItem]setLeftBarButtonItem:mainMenu];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
if (mainMenu == [[self navigationItem]leftBarButtonItem])
{
[[self navigationItem]setLeftBarButtonItem:nil];
}
}
这是我在主视图中选择一行时加载详细视图的方式:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:webViewController];
[details replaceObjectAtIndex:1 withObject:detailNav];
self.splitViewController.viewControllers = details;
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.window.rootViewController = self.splitViewController;
我已将此添加到 viewDidLoad 并且该按钮现在显示,但我不确定如何让它显示主视图。
mainMenu = [[UIBarButtonItem alloc]init];
[mainMenu setTitle:@"Menu"];
self.navigationItem.leftBarButtonItem = mainMenu;
这是我从左侧滑动以显示主视图时的样子。
我设法让一个左按钮出现,但现在我不知道如何让它打开主视图。这是我显示按钮的方式:
mainMenu = [[UIBarButtonItem alloc]init];
[mainMenu setTitle:@"Menu"];
self.navigationItem.leftBarButtonItem = mainMenu;