开发者

Custom UITableViewCell doesn't update its subviews immediately, why?

I have a custom UITableViewCell with, among other things, a label and an imageView. If the table view is the visible view and it has a cell on it, if I programmatically update the label's text and the imageView's image and log when I do it, it takes about 4 seconds AFTER I see the notification in the logs for the label and image to update. Here is the order of what happens and how:

-Load the view containing the table and one custom cell开发者_如何学C

-Write a file to disk using and NSOperation (and queue)

-When the NSOperation is finished writing the file it fires a NSNotification (defaultCenter) which tells the cell's view to update the label and image AND I set [self setNeedsDisplay]

-Here I see in my logs that the cell has gotten the notification AND finished setting the new values

-~4 seconds later the cell's view actually updates.

What gives?


The solution to my particular problem hinged on the way in which I'm updating the data, I'm using an NSOperation (and queue) to send a notification, the notification responder then updates the view. Problem is an NSOperation technically lives on another thread so what I should have done is this:

-Write a file to disk using and NSOperation (and queue)

-When the NSOperation is finished writing the file it fires a NSNotification (defaultCenter), the responder should then performSelectorOnMainThread a method that does the actual updating of the view

Did this and my cell updates right away.


You should call reloadRowsAtIndexPaths:withAnimation: to update a particular cell in the table view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜