I am designing an application with a tab bar at the bottom, representing 2 different sets of data that are the focus of my app. These sets are both of the same datatype but different collections (one is assigned entities, the other is nearby entities, but “entity” is the same type for both). Within each view controller there is also a toggle at the top for different views of that same data (one for a thumbnail-style view and another for a map view).
Based on my understanding that you wouldn’t use a 2-button tab bar controller with 1 shared instance of the same view controller across both tabs, I currently have the code split into 2 separate view controllers, one for “assigned entities” and one for “nearby entities”. The problem is the code here is exactly the same in each view controller. All that differs is the specific collection of entities. What I would like to do ideally is have 1 view controller with 2 arrays, 1 for each set of data, and have the data being used to populate the views change depending on which tab the user is on. Does anyone have any advice on doing this correctly? This certainly can’t be that unique of an issue but I’m not finding anything online to address this exactly. Typically I would think there’s something wrong with my initial design, running into a problem like this, but I think my design is sound and the approach I want to take is reasonable, but I’d like some help figuring out how to do this correctly with a tab bar controller.
Thanks.
Just have the one view controller class that knows how to handle your “entities”. Create two instances of the same class, one for each tab. Assign each view controller the appropriate set of entities.