具有多个视图控制器的 PopoverController 中的 UISegmentedControl
我希望将 UISegmentedControl 嵌入到 PopoverController 中,类似于此问题中所描述的内容: UISegmentedControl 嵌入 UINavigationBar/Item
不同之处在于,我想在 UINavigationBar/Item 中显示的每个视图都有一个不同的视图控制器弹出窗口,具体取决于分段控件上选定的索引。我不确定我会如何去做这件事。每当我尝试将新视图推送到根视图控制器顶部时,UISegmentedControl 就会消失。我只想在两个视图控制器之间切换,同时保持 UISegmentedControl 可见。这可能吗?
提前致谢!
I would like to have a UISegmentedControl embedded in a PopoverController, similar to what is described in this SO question : UISegmentedControl embedded in a UINavigationBar/Item
The difference is that I have a different view controller for each view that I want to show in the popover, depending on the selected index on the Segmented Control. I'm not sure how I would go about doing this. Whenever I try to push a new view on top of the root view controller, the UISegmentedControl disappears. I would just like to switch between the two viewcontrollers, while keeping the UISegmentedControl visible. Is this even possible?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果segmentBar上的每个段都有不同的viewController,则必须使用容器viewController,将每个viewController的视图添加为自身的子视图,或者将其视图设置为viewController的视图的视图。例如:
您可以只设置 self.view = test1.view,而不是将其添加为子视图。显然,您将使用容器视图来初始化 navController 并将该 navController 放入弹出窗口中。希望这有帮助!
If its a different viewController for each one of the segments on the segmentBar, you'll have to use a container viewController that adds the views of each of the viewController as a subview on itself or sets its view to that of the viewController's view. For example:
Instead of adding it as a subView, you might be able to just set
self.view = test1.view
. Obviously, you would use the container view to initialize the navController and put that navController inside the popover. Hope this helps!如果您使用presentModalViewController方法在屏幕上显示新的视图控制器,它将始终覆盖整个屏幕及其下方的内容。这就是它的工作原理。
根据文档:
做到这一点并且仍然能够控制视图控制器如何定位的方法是创建您自己的演示方法。
If you are using
presentModalViewController
method to show your new view controller on the screen, it will always cover the entire screen and what ever is underneath it. That's just how it works.As per docs:
The way to do it and still being able to control how the view controller is positioned is to create your own presentation method.