I built a simple app to view movie listing from rotten tomatoes(as a part of learning ios development)https://raw.githubusercontent.com/koldkoder/movie_listing/master/rotten_tomatoes.gif
I am trying to add tab control. One tab would list current box office movies, and second tab to list movies out on DVD recently. Both Views are exactly same, just they get data from different api endpoint. I want to use UITabBarController to implement this functionality. But i dont want to create two duplicate Viewcontrollers, instead use one for both the purpose. What is the right way of doing this, using storyboard, and code.
This is pretty straight forward. Create one UIViewController that takes a view type param in initializer like this:
typedef NS_ENUM (NSInteger, MediaViewType) {
MediaViewTypeBoxOffice = 0,
MediaViewTypeDVD
};
- (id)initWithViewType:(MediaViewType)iViewType;
In the implementation file, handle your view & functionality based on passed view type. Then add your view controller's instances to UITabBarController
:
MyMediaViewController *vc1 = [MyMediaViewController alloc] initWithViewType: MediaViewTypeBoxOffice];
MyMediaViewController *vc2 = [MyMediaViewController alloc] initWithViewType: MediaViewTypeDVD];
self.tabBarController.viewControllers = @[vc1, vc2];