UITabelView advanced (custom Cell), uitabelviewcell

Source: Internet
Author: User
Tags types of tables

UITabelView advanced (custom Cell), uitabelviewcell

Customize a Cell

When we want to display complex data, such as a button chat interface or a news list, the system's lines cannot meet our requirements. In this case, we can customize this line, show more complex structure styles.

A custom cell is a subclass of UITabelViewCell. It encapsulates the control creation on the cell in the subclass, simplifies the code in UIViewController, and adds the child view control to the contentView of the cell.

How to display the information in the model

The cell declares a model attribute. viewController obtains the Model object and assigns the Model attribute to the cell.

Cell re-writes the setter method of the Model, and assigns the content in the Model object to each control.

M and V do not communicate directly, and C is responsible for communication between M and V.

 

Multiple types of CELL Mixing

In development, multiple types of cells are commonly used in a tableView. Normally, each type of cell has different layout styles.

Generally, the tabelView: cellForRowAtIndexPath: method determines the type of cell to be used based on different models.

Each type of cell must define different reuse identifiers. During cell reuse, the reuse identifiers are used from the reuse queue to determine the type of cell.

For example, we define a ComposeCel type identifier and a ReceivedCell type identifier.

Then, different types of tables are retrieved from the reuse queue based on different identifiers.

 

 

Cell adaptive height

Previously, the cell we used was always the same height or fixed height for a row. However, in actual development, we often need to change the height of the cell dynamically based on the text length in the Model.

First, obtain the text height.

The calculated text height is the same as the font used for label display.

The label width must be the same as the specified width used for calculation, so that the label height happens to be sufficient when the text is displayed in the label.

TableView: heightForRowAtIndexPath:

Related Article

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.