Building Lightweight table View considerations [UIKit]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.