Articles from Objcio site
First, usethe childViewController
will table viewcontroller as child View Controller add to other view Controller View Controller view
Second, allow the cell to be reused
For complex cells or when there are multiple model objects that require the same type of cell representation. Then we can consider reusing the cell.
Third,the datasource of tableView isdecomposed into a separate class
Most of the DataSource in UITableView are the operations of an array. The ability to move the code related to an array operation into a separate class.
can use Block or delegate to set a cell.
Add
1 , when separating, be careful to separate the implementation details of the view layer from the controller layer. Delegate must clear what state a view should show, but it should not know how to change the structure of the view or set some properties for some subviews to get the correct state, all of which should be encapsulated inside the view, and then provide some simple API
2 , for a table There are several types of cell, datasourcein view. We need to infer the type of the cell and then distribute the appropriate method.
This is similar to the strategy pattern.
3, simply speaking, tableViewControllerThe decision of a facilitator and demodulator should be played on the model layer and the view layer, and the controller should not be concerned with the apparent viewlayers and the model layers of the task. Ability to use delegate, block, dataSourceMake TableViewControllerbecome more compact.
Put business logic and view logic in a more appropriate place. The implementation details in and out of the controller layer are encapsulated into simple APIs.
Building Lightweight table View considerations [UIKit]