现在我的代码允许我隐藏代表rootView控制器的侧栏。当我进入横向模式时,“根列表”按钮被“隐藏侧边栏”按钮取代,当单击它时,它会从splitView中删除RootViewController。以下是AppDelegate中的代码:
//Thanks to Alice McGregor for the code!!!
- (IBAction)toggleSplitView:(id)sender {
if ( [window.subviews containsObject:splitViewController.view] ) {
[splitViewController.view removeFromSuperview];
splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController, rootViewController, nil];
[window addSubview:detailViewController.view];
[(UIBarButtonItem *)sender setTitle:@"Show Sidebar"];
} else {
[detailViewController.view removeFromSuperview];
[detailViewController.view setTransform:CGAffineTransformIdentity];
splitViewController.viewControllers = [NSArray arrayWithObjects:rootViewController, detailViewController, nil];
[window addSubview:splitViewController.view];
[detailViewController.view sizeToFit];
[(UIBarButtonItem *)sender setTitle:@"Hide Sidebar"];
}
}
当选择隐藏侧边栏按钮时,这将删除rootView(表)。但是,当您切换到纵向模式时,根列表按钮不在那里,而是由“显示侧边栏”按钮替换。
我需要这样做,以便在横向模式下,表格被隐藏,但您仍然可以在纵向模式下选择根列表按钮。有什么想法吗?