I'm wondering which is the better way to implement a view which is designed to have complicated subview hierarchy, say a view with one sub view on left and one sub view on right, the left subview has X number of sub-subviews in one column, the right subview has Y number of sub-subviews in a row. (X and Y varies)
Two ways to implement it:
- Custom left and right views (ie. UIView subclass), custom left sub-subview, custom right sub-subviews, the root view only deals with custom left and right views, and they configure their sub-subviews
- Only one view with a column of views (ie left view's sub-subview) on left and a row of views (ie right view's sub-subview) on right
First approach: pros:
- clean hierarchy means better maintainability.
- responsibilities distributed over subviews, so less complication in each view
cons:
- nested subviews hierarchy
- may have worse performance due to auto-layout
- delegation chain is more difficult, consider each subview as a button which need to perform certain action, the custom view need to delegate the action all the way back to root view
Second approach: pros:
- less subviews
- may have better performance
- easy delegation chain compared to 1st approach
cons:
- hard to maintain / modify, as all subviews are in one level, especially with auto-layout
- messy code base since all views are in one base view
Looks like 1st approach is better, but it still has several cons, is there a completely new way to implement it which copes with all the cons?