我有一个 UINavigationController 作为我的 rootViewController,它包含一个 UIViewController(为了讨论,我将其称为项目)。在项目中,我有一个按钮,当单击它时,我想加载一个 UISplitViewController - 最好从底部向上滑动,尽管这只是一个不错的功能。
在 UISplitViewController 中,我有一个“关闭”按钮,我想删除 UISplitViewController 重新显示项目。
根据我的阅读,UISPlitViewControllers 必须是 rootViewControllers。考虑到这一点,到目前为止我的代码如下。
应用委托
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
...
// LOAD THE PROJECTS PANEL ROOT VIEW CONTROLLER INTO THE WINDOW
ProjectsListViewController *projects = [[ProjectsListViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:projects];
[window setRootViewController:navigationController];
[window makeKeyAndVisible];
return YES;
}
项目视图控制器
-(IBAction)loadDetails
{
ProjectNavigationController *projectNavPanel = [[ProjectNavigationController alloc] init];
ProjectDetailController *projectDetailPanel = [[ProjectDetailController alloc] init];
ProjectSplitViewController *splitRootController = [[ProjectSplitViewController alloc] init];
[splitRootController setViewControllers:[NSArray arrayWithObjects:projectNavPanel, projectDetailPanel, nil]];
[[self view] removeFromSuperview];
[[appDelegate window] setRootViewController:splitRootController];
}
UISplitViewController 导航
- (void)loadProjects
{
// LOAD THE PROJECTS LIST BACK INTO VIEW
ProjectsListViewController *projectsList = [[ProjectsListViewController alloc] init];
[[[self parentViewController] view] removeFromSuperview];
[[appDelegate window] setRootViewController:projectsList];
}
现在,我知道这是错误的,不出所料,它会对其他方法产生不利影响。事实上,当我输入这个时,我注意到 Projects 页面在启动时被加载到 navigationController 中,但在 splitViewController 关闭时直接放置在窗口上。任何人都可以通过解释实现这一目标的正确方法来帮助我吗?
谢谢