从 UINavigationController 切换到 UISplitviewController
Posted
技术标签:
【中文标题】从 UINavigationController 切换到 UISplitviewController【英文标题】:Switch from UINavigationController to UISplitviewController 【发布时间】:2011-11-16 18:20:49 【问题描述】:我有一个UINavigationController
提供几个UIViewControllers
。然后我想切换到UISplitviewController
。
所以我在我的 app-Delegate 中实现了一个方法 useSplitViewController
,我从上一个 UIViewController
调用它。它显示SplitView
,但我无法旋转我的设备。我的SplitviewController
中的ViewController
s 没有得到旋转事件。我的错误是什么,我该如何解决?
-(void)useSplitViewController
[self.menuViewController.view removeFromSuperview];
self.menuViewController = nil;
self.navcon = nil;
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.navcon = [[UINavigationController alloc] init];
self.menuViewController = [[MenuViewController alloc] init];
self.menuViewController.appDelegate = self;
[self.navcon pushViewController:self.menuViewController animated:NO];
[window addSubview:self.menuViewController.view];
[window makeKeyAndVisible];
//[self useSplitViewController];
return YES;
【问题讨论】:
【参考方案1】:需要设置窗口的根视图控制器:
替换
[window addSubview:self.splitViewController.view];
与,
[window setRootViewController:self.splitViewController];
【讨论】:
非常感谢。我不得不对 UINavigationViewController 做同样的事情,然后它就起作用了!以上是关于从 UINavigationController 切换到 UISplitviewController的主要内容,如果未能解决你的问题,请参考以下文章
从 UINavigationController 切换到 UISplitviewController
从UINavigationController中控制UINavigationItem内容
从 UINavigationController 设置 UITabBarItem 标题?
如何从 UINavigationController 隐藏 UINavigationBar?