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

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 similar to what we have in a navigation based application? That way I won't have to create a different view controller for each tab.

Upvotes: 0

Views: 1459

Answers (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

Upvotes: 0

ader
ader

Reputation: 5393

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 :)

Upvotes: 0

Related Questions