如何用 UISplitView 控制器替换 UIViewController?

发布于 2024-09-13 07:22:42 字数 221 浏览 3 评论 0原文

我的是一个普通的视图控制器应用程序。当我单击此 mainView 上的按钮时,它会添加第二个视图(不同的 xib)作为 mainView 的子视图。我希望将第二个视图替换为分割视图。所以这意味着我应该用 UISplitViewController 替换第二个视图控制器,不是吗?

我可以这样做吗?是否可以像 v 添加 viewcontroller 的视图一样添加 splitviewcontroller 的视图?

Mine is a normal viewcontroller application. When I click a button on this mainView, it adds a 2nd view(a different xib) as a subview to the mainView. I want this 2nd view to be replaced by a splitview. So it means I should replace the 2nd view controller with a UISplitViewController, isnt it?

Can I do that? Is it possible to add a splitviewcontroller's view like v add a viewcontroller's view?

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

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

发布评论

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

评论(2

ㄟ。诗瑗 2024-09-20 07:22:42

您应该知道,目前,UISplitViewController 的唯一官方用途是作为应用程序的视图控制器;苹果并不打算让它成为一个子视图控制器。显然,这是由于处理 iPad 旋转的错误造成的,可能会在以后修复。因此,您应该避免将 UISplitViewController 的视图添加为任何内容的子视图。

You should be aware that, currently, the only official usage of UISplitViewController is as a root view controller of an application; Apple does not intend for it to be a child view controller. Apparently, this is due to bugs with handling rotation of the iPad, and may get fixed at a later date. So you should avoid adding a UISplitViewController's view as a subview to anything.

╭ゆ眷念 2024-09-20 07:22:42

您可以对 UIViewController 进行子类化,然后在 init 中:

UIViewController *left = ...;
UIViewController *right = ...;
UISplitViewController *splitVC = ...;
splitVC.viewControllers = [NSArray arrayWithObjects:left,right,nil];
self.view = splitVC.view;

return self;

然后将其用作普通的 UIViewController。

You can subclass UIViewController and then in the init:

UIViewController *left = ...;
UIViewController *right = ...;
UISplitViewController *splitVC = ...;
splitVC.viewControllers = [NSArray arrayWithObjects:left,right,nil];
self.view = splitVC.view;

return self;

Then just use this as a normal UIViewController.

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