在 UITabBarController 内的 UINavigationController UINavigationBar 上设置 UISegmentedControll 的正确方法
标题几乎描述了一切。
问题在于 UISegmentedControll 回调(按钮按下)的处理。 如果所有嵌套视图的内容类型相同(即一些 UITableViewController),那么我可以切换数据源并重新加载表。
然而事实并非如此,我在那里有 3 个非常不同的视图,允许基于 NavigationController 进行进一步的深入/交互。
因此,我设置 ATM 的方法是,有一个“容器”类,我将所有 UINavigationController 放入其中。它们都共享相同的一个 UISegmentedController,然后我将回调重定向到容器视图控制器。这感觉不太好。
此外,当用户点击选项卡栏图标时,还存在一个问题,导航控制器会弹出到根目录,即......空容器视图。
这是我想要实现的目标的图片:
The title pretty much describes it all.
The problem being the handling of the UISegmentedControll callbacks (button presses).
If the content type of all of the nested views was the same (i.e. some UITableViewControllers) then I could just switch dataSource'es and reload the tables.
However this is not the case, I have 3 very different views in there that allow further drilldown / interaction based on the NavigationControllers.
So the way I have this set up ATM is that there is a "container" class that I put all of the UINavigationControllers in. They all share the same and one UISegmentedController and I redirect the callbacks to the container view controller. This does not feel too good at all.
Additionally there is a problem when the user taps on the tab bar icon, the navigation controller pops to root which is ... the empty container view.
Here's a picture of what I want to achieve:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的一个应用程序中,我有一个表视图,它由三个单独的 NSMutableArray 的数据填充。我有条件地在 cellForRowAtIndexPath 中设置单元格内容,并有条件地在 numberOfRowsInSection 中获取 3 个不同的计数。虽然这不是您想要的具体内容,但您不需要拥有初始示例中所示的 3 个不同的数据源。
你的直觉是正确的。它看起来确实过于复杂。
使用一个 NavigationController 并仅在 NavigationController.view 上交换 addSubview/removeFromSuperview 怎么样?
In one of my apps I have a single table view that is populated from data of three separate NSMutableArrays. I conditionally set the cell contents in cellForRowAtIndexPath, and conditionally get 3 different -counts in numberOfRowsInSection. While this isn't specifically what you are looking for, you don't need to have 3 different data sources as expressed in your initial example.
Your instincts are correct. It does seem overly complex.
How about using one NavigationController and just swapping addSubview/ removeFromSuperview on the NavigationController.view?
我在最近的 iPad 应用程序中遇到了类似的功能要求,我使用的解决方案在以下链接中 - 本质上,我实现了一个“管理”视图控制器,它根据分段控件的选定索引添加/删除子视图,正确处理事件。
我通过将“管理”视图控制器作为参数传递到子视图视图控制器中,并让这些控制器回调父视图以推送到导航堆栈上,解决了导航控制器问题。
我特别喜欢该解决方案的一点是,它让我可以将每个段的相应视图的代码分开,而不是在单个重载的视图控制器中混乱。
详细信息如下: UISegmentedControl 最佳实践
好问题伙伴,希望有所帮助。
I've came across a similar feature requirement in a recent iPad application, the solution I used is in the following link - essentially, I implemented a 'managing' view controller, that adds/removes subviews based on the selected index of the segmented control, with correct handling for events.
I solved the navigation controller issue by passing the 'managing' view controller into the subview view controllers as a parameter, and having those controllers call back on the parent to push onto the navigation stack.
What I particularly like about the solution is that it lets me keep the code for each segment's corresponding view separate, and not jumbled within a single overloaded view controller.
Details are here: UISegmentedControl Best Practice
Good question mate, hope that helps.