使用 Interface Builder 添加 UIView,删除,然后添加到另一个视图
由于选项卡视图中存在拆分视图的问题,我已将应用程序创建为选项卡视图,并尝试在我的选项卡之一中模拟拆分视图功能。
我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要删除左侧视图?您可以隐藏它并为主视图设置框架。
Why you are removing left side view? you can just hide it and set frames for main view.
您是否在任何地方保留 playMakerToolsView?如果不是,当您从超级视图中删除它时,它可能会被释放。
Are you retaining playMakerToolsView anywhere? If not, when you remove it from the superview it is potentially up for dealloc'ing.