I am wondering what is the proper way of showing countdown in fairly complex UITableViewCells, in each cell one countdown with different time.
I could have NSTimer for each cell separately but then the cells wouldnt update at same time. I could have one NSTimer for all cells but calling reloadData on uitableview is fairly expensive to do every second, isnt it?
Obviously the needs to be updated only in visible cells.
Any ideas, best practice, know how on this matter?
Some thoughts on how I would implement this:
update
method in that class. This method updates the label.TableViewController
classindexPath
. UITableView.CellForRowAtIndexPath
returns nil
for cells which aren't visible.update
method for each of these visible cells.An alternative approach would be to use NSNotificationCenter
.
Your view controller would post a notification whenever your time period has elapsed.
Each of your UITableViewCell would register for this notification and update its display in response.
Note that to prevent memory leaks you need to remove each UITableViewCell as an observer as it goes off-screen. This can easily be done in the UITableViewDelegate
's
tableView:didEndDisplayingCell:forRowAtIndexPath:
method.
The advantage of doing this is that you don't need to subclass UITableViewCell nor to try and keep track of each cell that needs refreshing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With