iOS 8 Auto height cell not correct height at first load

前端 未结 5 1520
遥遥无期
遥遥无期 2020-12-28 15:54

I have an iOS 8 application where I have a search results page that each cell is autosized based on the height of a certain label. However, after the view first loads the c

5条回答
  •  粉色の甜心
    2020-12-28 16:06

    I had the same problem and fixed it by moving assignments to the cell's UILabels' text properties (being the only components that could influence the height calculation in my particular cell) to:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    instead of:

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    Before doing this I noticed that the cell height would be correctly calculated if a cell was scrolled momentarily off-screen and then back into view. Most likely because, at that point, the cell had the necessary information regarding the UILabel content determining the final height.

提交回复
热议问题