使用 Interface Builder 添加 UIView,删除,然后添加到另一个视图

发布于 2024-11-16 01:25:55 字数 586 浏览 1 评论 0原文

由于选项卡视图中存在拆分视图的问题,我已将应用程序创建为选项卡视图,并尝试在我的选项卡之一中模拟拆分视图功能。

我已经在 Interface Builder 中以横向方式创建了分割视图的左侧面板。当用户更改为纵向时,我想以编程方式从视图中删除左侧面板,并将其添加到要从工具栏按钮启动的弹出面板中。当然,反之亦然。

我以为我知道该怎么做,但它不起作用。我创建了一个 UIViewController 来执行以下操作:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [playMakerToolsView removeFromSuperview];
    [self.view addSubview:playMakerToolsView];
}

...其中 playMakerToolsView 是对从 Interface Builder 添加的 UIView 的引用。

但我发现当我启动这个弹出窗口时,它似乎没有正确显示。弹出窗口是空白的。

我对 iOS 开发还比较陌生,所以我可能遗漏了一些明显的东西。如果你能指出我正确的方向那就太好了。

Due to problems having a split view within a tab view, I have created my application as a tab view and am trying to simulate split view functionality within one of my tabs.

I have created the left hand side panel of the split view in the Interface Builder in the landscape orientation. When the user changes to portrait, I want to programmatically remove the left hand side panel from the view and add it to a popover panel to be launched from a toolbar button. Then vice versa, of course.

I thought I knew how to do this, but it's not working. I've created a UIViewController which does this:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [playMakerToolsView removeFromSuperview];
    [self.view addSubview:playMakerToolsView];
}

...where playMakerToolsView is the reference to the UIView added from the Interface Builder.

But I'm finding when I launch this popover, it doesn't seem to show correctly. The popover is blank.

I'm relatively new to iOS development so I'm probably missing something obvious. If you could point me in the right direction that'd be great.

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

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

发布评论

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

评论(2

执着的年纪 2024-11-23 01:25:55

为什么要删除左侧视图?您可以隐藏它并为主视图设置框架。

Why you are removing left side view? you can just hide it and set frames for main view.

怼怹恏 2024-11-23 01:25:55

您是否在任何地方保留 playMakerToolsView?如果不是,当您从超级视图中删除它时,它可能会被释放。

Are you retaining playMakerToolsView anywhere? If not, when you remove it from the superview it is potentially up for dealloc'ing.

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