Similar to Netease News and lofter, I think the effect of multi-label scrolling switching is achieved by adding tableview to scrollview, but this realization will make ViewController bloated and the realization of delegate and datasource confusing. I would like to know what kind of suggestions Iko Iko people have for the construction of this interface, which can improve code reuse and put code stripping in the right place.I really want to write code with clear and beautiful structure, smecta!
The list corresponding to each label can be a viewController, which is responsible for the interaction of the contents of this list and everything. ScrollView inside is installed with viewController.view
The viewController where scrollView is located can be called containerViewController, which actually serves as a container such as NavigationController. The specific content can be called contentViewController.
Its advantages are:
- The same contentVC can be freely removed and installed in different containers to reduce coupling, or as the title owner said, “it can improve code reuse and strip code to the right place.”
- You can dynamically adjust the quantity of contentvc, and the style can also be different. as long as it is VC, netease news in the main picture is undoubtedly the leader in doing so.
- Through the principle of “crossing the river with two boards”, three view can be used as the middle layer between contentVC and scrollView, so that no matter how many contentVC (e.g., netease news adds many labels), only three are loaded on scrollView at the same time.
- There must be, I didn’t think of at the moment. . .
Generally speaking, this kind of structure can be called “clear and beautiful”, but it also depends on the standard of the implementer. If it is not done well, it will lead to many problems and it is done well. . . How useful is Netease News to you:)