Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for updating table cells based on notifications

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.

like image 702
Shizam Avatar asked Feb 24 '11 01:02

Shizam


1 Answers

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.

like image 60
Jeff Kelley Avatar answered Oct 03 '22 12:10

Jeff Kelley