从 UINavigationController 切换到 UISplitviewController

发布于 2024-12-16 11:59:53 字数 1783 浏览 0 评论 0原文

我有一个 UINavigationController,它提供了几个 UIViewController。然后我想切换到 UISplitviewController 。

因此,我在我的应用程序委托中实现了一个方法 useSplitViewController,我从最后一个 UIViewController 调用该方法。它显示了 SplitView,但我无法旋转我的设备。我的 SplitviewController 内的 ViewController 没有获得旋转事件。我的错误是什么?我该如何解决?

 -(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;
}

I have a UINavigationController presenting a couple of UIViewControllers. Then I want to switch to a UISplitviewController.

So I implemented a method useSplitViewController in my app-Delegate that I call from my last UIViewController. It shows the SplitView, but I can't rotate my device. The ViewControllers inside my SplitviewController don't get the rotation-event. What is my mistake and how can I solve it?

 -(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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2024-12-23 11:59:53

您需要设置窗口的根视图控制器:

替换

[window addSubview:self.splitViewController.view];

为,

[window setRootViewController:self.splitViewController];

You need to set the root view controller of the window:

replace

[window addSubview:self.splitViewController.view];

with,

[window setRootViewController:self.splitViewController];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文