Customize cell by code (cell height inconsistency)

Source: Internet
Author: User

During iOS development, the system's uitableviewcell has many limitations. Therefore, in most cases, we need to customize a tableviewcell. What's more complicated is that the cell height of each row is not certain, it is determined by the cell content. A typical example is Sina Weibo. Here we can provide a custom tableviewcell idea.

1. Create a class that inherits from uitableviewcell.
2. Override initwithstyle: reuseldentifier: Method
^ Add all child controls to be displayed (you do not need to set the data and frame of the Child control. The child control must be added to contentview)
^ Perform one-time attribute setting for sub-Controls (some attributes only need to be set once, such as fonts and fixed images)
3. provide two models
^ Data Model: stores text and Image Data
^ Frame model: stores data models, frames of all child controls, and height of cells
4. Cell has a frame model (data models are not directly available)
5. Override the setter method of the frame model attribute: In this method, set the display data and frame of the Child control.
6. the initialization of frame model data has taken the form of lazy loading (the frame model data corresponding to each cell is loaded only once)

Customize cell by code (cell height inconsistency)

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.