TableView interface construction of unequal cell

Source: Internet
Author: User

I. Building the interface

1. Interface Analysis
Analyze the hierarchical structure of the interface and what controls the interface should use to build

2. Interface hierarchy
After analysis, we can divide this interface into four modules (TopView middleview commentview Bottomview)
This complex interface, which we generally call: unequal cell

3. How to build the interface
Analysis found that most of the interface is not certain (text height, there are no pictures, comments)
So we use a pure code approach to build the interface
But after we've divided the complex interface, the contents of some small modules are fixed.
These fixed small modules we can use Xib to build

4. Some modules are not sure whether to show, how to deal with the construction?
When we create the cell, we add all the modules and hide them when we don't need them.

5. Where is the code that created the cell written?
The first thing to do is to customize the cell, generally create a cell we want to do cache processing, so cell creation is generally registered
The essence of registering through a class is to call the cell's Initwithstyle: Method
-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (Nullable NSString *) reuseidentifier
We just need to write the code in this method.
Note: Call this method and be sure to call the Super method

6. How to determine if a cell is registered through a class it must call Initwithstyle: Method
Override this method in a custom cell class, and print the information to determine

7. Why not create a cell in the initWithFrame method?
The initWithFrame method calls only if the control is created through the Init method or the initWithFrame method.
And we created a cell that was created by using the Initwithstyle: method

8.cell so many modules, how to build?
The building of a module, a module
Build the TopView module first (build the interface, load the data, process the data), finish the business logic and then build the next module

Two. TopView Interface Construction
1. Construction Method Xib Construction

2. What controls are used to build
Avatar with ImageView, nickname and time and text, respectively, with a label

3. Request data
View interface documentation, send network requests, parse data, display data
To display the data, set the cell's frame

How is 4.cell frame determined?
Xib cannot determine the cell's frame, so it's okay to have more cells in xib, but be sure to constrain the child controls
Xib the size of the neutron control is the actual size shown
So: When we load xib, we need to reset the cell's frame

How is the height of 5.cell determined?
The cell's height needs to be calculated manually.

Where is the height of 6.cell calculated?
6.1 can no longer be computed in the Cellforrowatindexpath method (late)
6.2 also cannot calculate cell height in Heightforrowatindexpath, this method call frequency is very high

7. What are the requirements for calculating the cell height?
7.1 Be sure to calculate the cell height before the Heightforrowatindexpath call
7.2 Only need to calculate once

8. Where is the cell height calculated?
When the request data is successful, the cell height is calculated.
Save the cell's height to an array, and then return the corresponding cell height in the array in the Heightforrowatindexpath method
Disadvantages of this approach: there is too much code in the controller, and the controller is more heavyweight

9. You can also calculate the cell height in the model
In general, we do cache processing, typically caching the model
If you put the calculation code inside the model, then the cache data is larger, the performance is not good
There's another way: You can use the MVVM framework to calculate cell heights

TableView interface construction of unequal cell

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: 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.