This may be a solution that does not reload the cells at all. Just make the cells listen for the update notification and change their label accordingly. I assume that you are a subclass of UITableViewCell and assign the property storedDate to the property. This property will be set when preparing the cell.
The timer just starts the notification.
Do not forget to unregister a cell from the notification center in dealloc
Here is a brief example.
A view controller containing your TableView:
class ViewController: UIViewController, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var timer: NSTimer! //MARK: UI Updates func fireCellsUpdate() { let notification = NSNotification(name: "CustomCellUpdate", object: nil) NSNotificationCenter.defaultCenter().postNotification(notification) } //MARK: UITableView Data Source func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentifier = "CustomCell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as! CustomTableViewCell cell.timeInterval = 20 return cell } //MARK: View Lifecycle override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.timer = NSTimer(timeInterval: 1.0, target: self, selector: Selector("fireCellsUpdate"), userInfo: nil, repeats: true) NSRunLoop.currentRunLoop().addTimer(self.timer, forMode: NSRunLoopCommonModes) } deinit { self.timer?.invalidate() self.timer = nil } }
Custom Cell Subclass:
class CustomTableViewCell: UITableViewCell { @IBOutlet weak var label: UILabel! var timeInterval: NSTimeInterval = 0 { didSet { self.label.text = "\(timeInterval)" } }
I am sure this example does not match your application logic. Just showing how everything glows together.
source share