gpt4 book ai didi

ios - 在 Objective-C 中从 UIViewController 显示一个 SplitViewController

转载 作者:行者123 更新时间:2023-12-01 17:55:22 24 4
gpt4 key购买 nike

我正在开发一个带有单个按钮的 ViewController(登录应用程序),当我按下此按钮时,我希望我的 UISplitView 如下所示:

- (IBAction)loadSplitViewController:(id)sender {

[self showSplitViewController];
}

为创建我的 splitViewController 而开发的代码是这样的:
-(void)showSplitViewController{

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle: nil];

LeftViewController *leftViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
RightViewController *rightViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"RightViewController"];

UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:rightViewController];

UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];

leftViewController.delegate = rightViewController;
splitViewController.delegate = rightViewController;

[self presentViewController:splitViewController animated:YES completion:^{}];
}

问题是......如果我用于显示我的 splitViewController 这一行:
[self presentViewController:splitViewController animated:YES completion:^{}];

给我一个错误

我也试过
[self.view addSubview:splitViewController.view];

但是这样我的 splitViewController 永远不会旋转,并且委托(delegate)也不能正常工作......而且我不希望我的 splitViewController 成为我的 viewController 的 subview ,我希望它看起来更像一个独立的 modalView

任何帮助我都会感激

提前致谢

最佳答案

Split View Controller 确实应该是窗口的 Root View Controller (事实上,Apple 说它必须是,尽管似乎有一些例子证明这不是真的)。您可以将窗口的 Root View Controller 切换为 Split View Controller ,而不是呈现它。

self.view.window.rootViewController = splitViewController;

关于ios - 在 Objective-C 中从 UIViewController 显示一个 SplitViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18906738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com