开发者

Best practice for updating table cells based on notifications

开发者 https://www.devze.com 2023-02-13 15:22 出处:网络
I have a table view of custom cells representing individual uploads and each cell has a progress indicator in it and a success/error icon.I want to update the cells as progress is updated and indicate

I have a table view of custom cells representing individual uploads and each cell has a progress indicator in it and a success/error icon. I want to update the cells as progress is updated and indicate if it was a success/failure. I do this by having my upload controllers broadcast NSNotifications for progress/success开发者_如何学运维/failure.

Is it better to:

A) have each cell have a NSNotification listener for these notifications and update the cell view

OR

B) have the table view controller have a NSNotification listener listen for these notifications and then set the values for each cell by getting cells with cellForRowAtIndexPath.

I guess it comes down to A is easier to implement but I'm wondering if there is a performance penalty to have so many listeners listening to those notifications and doing a 'IF this notification is about me...'. As opposed to B which only has one listener, and can be generalized to any multi vs single listener design.


You could set up Key-Value Observation (KVO) for your table view to handle row updates, then use it (with a custom UITableViewCell subclass) to update the cells with information from your objects. See Using KVO for Table Updates for an example of using KVO for section/row updates.

0

精彩评论

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