سؤال

I have a UITableView which is displaying update posts from various social networks. I have custom UITableViewCell subclasses, which have a custom UIView inside, which is responsible for drawing all the labels and images, similar to how Apple describes here: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW18

In this view's -layoutSubviews call, I find the size needed for the various labels, and set their frames accordingly. However, after scrolling for a little bit, it's obvious that -layoutSubviews is not being called when a cell is recycled, leading to some cells not having their label frame set big enough to display their content. When passing my data object through the cell to the custom view, I call [self setNeedsDisplay], which I believed would cause the cell to call -layoutSubviews.

How can I best ensure that the labels are properly resized for the content that gets sent to them?

هل كانت مفيدة؟

المحلول

If you want to force layout, send setNeedsLayout (not setNeedsDisplay) to the view. It sounds like you need to send [cell setNeedsLayout] in your tableView:cellForRowAtIndexPath: before returning the cell.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top