简体   繁体   中英

heightForRowAtIndexPath is not called after cellForRowAtIndexPath in iOS 7

I have a grouped UITableView whose cells' content is dynamic. I need to calculate the actual height I need for each cell in cellForRowAtIndexPath: method. I'm testing in both iOS 7 and iOS 8 devices and I'm finding that in iOS 8 the method heightForRowAtIndexPath: is called when cellForRowAtIndexPath: returns (and then, I have cell's height updated), but it is not called in iOS 7 (so all cell's height is always the same).

I wasn't able to find a solution for this problem... please, could somebody help me?

Thanks in advance

Your premise is faulty. If you are doing this correctly, then in both iOS 7 and iOS 8 (and in all systems before that, in fact), heightForRowAtIndexPath: is called before your call to cellForRowAtIndexPath: . In general what happens is that heightForRowAtIndexPath: is called for every row, before the first call to cellForRowAtIndexPath: . That way, the table has enough information for layout before it starts generating cells.

If you are seeing a difference in behavior, it may be because you are also using the estimatedRowHeight , which does behave differently in iOS 8 vs. iOS 7. So the easy solution is: don't do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM