简体   繁体   中英

Occasional problems with UITableView and heightForRowAtIndexPath

I have a UITableView with rows that dynamically update their height. I have the following method as a delegate of a UITextView in each cell of the UITableView:

-(void)textViewDidChange:(UITextView *)textView
{
[self resizeRow];
[self setNeedsDisplay];
[table beginUpdates];
[table endUpdates];
}

This method works fine for updating the table view row height as text is added to the text view. My problem comes when I update a UIImageView that is in the cell to increase its size. This requires a resizing of the height of the cell of the table which works fine, but from that point on whenever the [table begineUpdates] [table endUpdates] block is called, heightForRowAtIndexPath of the table view is no longer called. I'm not getting any errors or warnings and have no idea where else in the code to look. My question is then should heightForRowAtIndexPath always be called when a [table begineUpdates] [table endUpdates] block is called or are there cases where this doesn't occur and if so what are they?

Found the problem. There was a spurious [table endUpdates] ; call hidden in a method. This was obviously getting the [table beginUpdates]; [table endUpdates]; out of sync in some way. Feel much happier now.

This answer might help you, but in general heightForRowAtIndexPath will get called once when the cell is first displayed or upon a call to reloadRowsAtIndexPaths:withRowAnimation . It might be awkward to make that call from the cell, however, since the cell has no idea of its indexPath , but you can get the indexPath using a call to indexPathForCell: .

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