iOS Tab bar controller containing same Table views inside all tabs but different filtered data

人走茶凉 提交于 2020-01-06 07:53:05

问题


SOLVED: I think I figured it out on how to do it.

I added tags to each of my view controllers for each tab. Then in the viewDidLoad method on the view controllers, I can add a switch based on which tab's tag is selected: self.tabBarController.tabBar.selectedItem.tag

Issue:

I am pretty new to iOS development and need some feedback on this- Here is the scenario:

I am using storyboards for this. We have a navigation controller inside a tab bar controller. The Tab bar controller contains the same types Table views inside all tabs but the data is filtered differently.

For example Tab 1 will show all types of red fruits, tab 2 will show all kind of yellow fruits and so on.

Now since I am using storyboards, do I need to create 2 different master view controllers branching from the tab bar controller for each tab? Or can I just use the same master view controller for both the tabs?

Is there anything like an identifier on the segue which I can use specify which tab was selected? I couldn't find it on the segue from the tabbarcontroller to the navigation controllers.

When a tab is selected, is there any method like "prepareforsegue" where I can preset the filter on the destinationviewcontroller? something similiar to what we have in a navigation based application? That way I won't have to create a different view controller for each tab.

Thanks for the help!


回答1:


from here

in your UITabBarControllerDelegate delegate:

- (void)tabBarController:(UITabBarController *)tabBarController     didSelectViewController:(UIViewController *)viewController
{
  ...
}

I guess in there you could set a property on the appropriate viewController.

p.s. try to share your model across viewControllers too :)




回答2:


I added tags to each of my view controllers for each tab. Then in the viewDidLoad method on the view controllers, I can add a switch based on which tab's tag is selected: self.tabBarController.tabBar.selectedItem.tag



来源:https://stackoverflow.com/questions/12244711/ios-tab-bar-controller-containing-same-table-views-inside-all-tabs-but-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!