I am working on an app in which one View Controller has the responsobility of containing thre views.
- Each and every one of this view has a datasource of somme measurements.
- The views are in sync -> selectind one point in one view has a resemblence in other views.
- User can select in various options to disply in each of the views (e.g. 3 views but 5 view options.
Here is my current aproach to take in this situation:
- Create a component protocol -all views have to conform.
- Component for example is a UICollecytionView with details for the selections (which is made in other components).
- The component has a view property and is added dynamicaly to the container view of the view controller by the controller.
- Visible view controllers are synced by a sync manager - to which the visible view is registered by the view controller.
- Delegates are mostly implemented in the Component -> some events are exposed in a component delegate (user selected etc. so the sync manager can sync other views).
- The view controller is responsible for capturing a delegate from user selection of measurement batches (e.g. batch from a given day in another view controller) and then loads needed data and triggers the sync manager to give the selected batch to each of the visible components.
- The component is then responsible for presenting the batch (as well as loading/finding relevant points for the new batch if earlier batches had selected points)
Is this approach correct? Having the code of each component in the view controller would (and in the first approach did) clog the sense and clarity of it!
I also did read about View Controller Containment (so that if i understand correctly would mean crating a view controller for each option and handle that element inside the view controller and swap them for visible views on the screen). Then the user selection would trigger swapping a view controller responsible for a concrete selection of an option but then the sync would best be made by the parent view controller (am I correct).
Hope I am clear enough... although I am aware that the description is hazy but you should get the main idea.
Reasuming:
- What approach is better? The component seem like a good reusable components that i can pretty dynamically add to other view controllers etc.
- What are the possible pitfalls of each of these approaches if any?