Objective-c - Only the first few data sources are not displayed in the tableView. Dragging them downwards will display them completely. Why?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-02 09:29:21
0
1
615

The cell of tableView is added to calculate the height of the cell and call the proxy method, which is returned to the view controller.
When the server returns the data source, refresh the tableView.
However, the indexPaht of cellForRowIndexPath executed at this time starts from the fourth line,
The first few are skipped,
I tried to write the height of the cell as a fixed value,
The result is that the number of cells is normal.
What is the problem?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
迷茫

It should be that the height calculation is lagging.
The display order of tableView is roughly:
Request sectionNumber and numberForSection to get the total number of sections and cells. sectionNumbernumberForSection 获取一共有多少个section和cell。
请求 heightForRow:atIndexPath 获取即将显示在界面上的 cell 的高度。
然后请求 cellForRow 获取这个 cell 的实例。
然后设置 cell 的高度等,layout 之后调用 willDisplayRequest heightForRow:atIndexPath to get the height of the cell that will be displayed on the interface.

Then request cellForRow to get an instance of this cell.

Then set the height of the cell, etc., and then call callback methods such as willDisplay after layout, and then display it on the interface.

So when you refresh the tableView, the processing of the height part should be to first calculate the cell height according to the data source instead of letting the cell instance calculate it and then call back to the controller. Of course, you can also calculate in the cell. For example, there is a class method in the cell, which is calculated based on the incoming cell data, and the controller actively calls this method. The approximate code is as follows:

In the delegate implementation class of controller or tableView:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *cellData = self.dataSource[indexPath.row];
    return [MyTableViewCell cellHeightForData:cellData];
}
🎜MyTableViewCell:🎜
+ (CGFloat)cellHeightForData:(NSDictionary *)cellData
{
    // 根据 cellData 计算 cell 的高度
    return height;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template