objective-c - tableView中只不显示数据源的前几个,稍微向下拖拽就会显示完全,什么原因?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-02 09:29:21
0
1
545

tableView 的cell中添加了计算cell的高度并且调用代理方法,返回给视图控制器
当服务器返回数据源的时候,刷新tableView。
但是,此时执行的cellForRowIndexPath 的indexPaht 是从第四行开始的,,
将前边的几个给跳过了,
我试着将cell的高度写成定值,
结果cell的数量正常,
这会是什么问题?

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!