开发者

Proper way to setup a UISegmentedControll on UINavigationController UINavigationBar all inside UITabBarController

The title pretty much describes it all.

The problem being the handli开发者_如何学JAVAng 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:

Proper way to setup a UISegmentedControll on UINavigationController UINavigationBar all inside UITabBarController


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜