UISplitViewController & UINavigationController

璀璨夜空 2014-09-25 08:53:25
先贴代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];

//PHMessagingSplitViewController is a subclass of UISplitViewController
PHMessagingSplitViewController *tmpVC = [[PHMessagingSplitViewController alloc] init];

//problem here.
UINavigationController *tmpNav = [[UINavigationController alloc] initWithRootViewController:tmpVC];

self.window.rootViewController = tmpNav;
[self.window makeKeyAndVisible];

return YES;
}

为什么无法在程序中把PHMessagingSplitViewController push 到NavigationController?
程序运行后系统提示:Split View Controllers cannot be pushed to a Navigation Controller <UINavigationController: 0x7bf993f0>.

另外,通过UIStoryboard却可以做到!
请问有谁可以解释一下这个问题?
我想通过程序实现,而不用噁心的Storyboard.
...全文
259 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
璀璨夜空 2014-09-26
  • 打赏
  • 举报
回复
不过我已经用Storyboard实现了。只是不知道为什么Storyboad可以做,而程序中不可以。
璀璨夜空 2014-09-26
  • 打赏
  • 举报
回复
引用 7 楼 zhanglei5415 的回复:
[quote=引用 6 楼 wangxinghe 的回复:] [quote=引用 5 楼 zhanglei5415 的回复:] [quote=引用 4 楼 wangxinghe 的回复:] 但是就是不能通过程序实现。诡异的苹果开发!
在AppDelegate.h中, 将uisplitviewcontroller作为uiwindow的rootviewcontroller .如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
//PHMessagingSplitViewController is a subclass of UISplitViewController
    PHMessagingSplitViewController *tmpVC = [[PHMessagingSplitViewController alloc] init];

    self.window.rootViewController =tempVC;
    [self.window makeKeyAndVisible];
    
    return YES;
}
[/quote] 谢谢你的回复。不过我需要在最顶部显示NavigationBar。所以必须要用UINavigationController.[/quote] UISplitViewController 应该也是一个容器controller,左边的是Master, 右边的是Deitail. 指定Master和Detail 对应的控制器均为UINavigationController 不就可以了吗 ?[/quote] 最顶部显示,在Master Detail里面我不需要显示各自NavigationBar的。
璀璨夜空 2014-09-25
  • 打赏
  • 举报
回复
引用 5 楼 zhanglei5415 的回复:
[quote=引用 4 楼 wangxinghe 的回复:] 但是就是不能通过程序实现。诡异的苹果开发!
在AppDelegate.h中, 将uisplitviewcontroller作为uiwindow的rootviewcontroller .如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
//PHMessagingSplitViewController is a subclass of UISplitViewController
    PHMessagingSplitViewController *tmpVC = [[PHMessagingSplitViewController alloc] init];

    self.window.rootViewController =tempVC;
    [self.window makeKeyAndVisible];
    
    return YES;
}
[/quote] 谢谢你的回复。不过我需要在最顶部显示NavigationBar。所以必须要用UINavigationController.
ReyZhang 2014-09-25
  • 打赏
  • 举报
回复
引用 4 楼 wangxinghe 的回复:
但是就是不能通过程序实现。诡异的苹果开发!
在AppDelegate.h中, 将uisplitviewcontroller作为uiwindow的rootviewcontroller .如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
//PHMessagingSplitViewController is a subclass of UISplitViewController
    PHMessagingSplitViewController *tmpVC = [[PHMessagingSplitViewController alloc] init];

    self.window.rootViewController =tempVC;
    [self.window makeKeyAndVisible];
    
    return YES;
}
璀璨夜空 2014-09-25
  • 打赏
  • 举报
回复
但是就是不能通过程序实现。诡异的苹果开发!
璀璨夜空 2014-09-25
  • 打赏
  • 举报
回复
Storyboard 拖拽一个UINavigationController 作为起点,设置它的RootViewController为自己的PHMessagingSplitViewController就可以了。
璀璨夜空 2014-09-25
  • 打赏
  • 举报
回复
我通过Storyboard可以做到。只是不明白为什么不能通过程序实现。
ReyZhang 2014-09-25
  • 打赏
  • 举报
回复
苹果本身就不允许你将uisplitviewcontroller去push到uinavigationcontroller 中。 参考:http://stackoverflow.com/questions/6855454/how-can-we-push-uisplitviewcontroller-to-a-uinavigationcontroller
ReyZhang 2014-09-25
  • 打赏
  • 举报
回复
引用 6 楼 wangxinghe 的回复:
[quote=引用 5 楼 zhanglei5415 的回复:] [quote=引用 4 楼 wangxinghe 的回复:] 但是就是不能通过程序实现。诡异的苹果开发!
在AppDelegate.h中, 将uisplitviewcontroller作为uiwindow的rootviewcontroller .如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
//PHMessagingSplitViewController is a subclass of UISplitViewController
    PHMessagingSplitViewController *tmpVC = [[PHMessagingSplitViewController alloc] init];

    self.window.rootViewController =tempVC;
    [self.window makeKeyAndVisible];
    
    return YES;
}
[/quote] 谢谢你的回复。不过我需要在最顶部显示NavigationBar。所以必须要用UINavigationController.[/quote] UISplitViewController 应该也是一个容器controller,左边的是Master, 右边的是Deitail. 指定Master和Detail 对应的控制器均为UINavigationController 不就可以了吗 ?

29,030

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧