SWIFT - Reload UITableViewCell

I am having a problem trying to reload my UITableView from my TimersManager.swift file. TimersManager.swift is used to manage / manage all timers in my to-do / timers app. I am trying to update the UILabel to show the updated time when the timer goes off. For some reason, it won't update the table. Please see below and hopefully you can give me a nudge in the right direction. Thank.

top of listTableViewController.swift:

var prepMgr: listTableViewController = listTableViewController()
var cell:customCell!

 class listTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {


update func in listTableViewController: (this is caused by another func in my TimersManager.swift file)

    func update (indexPathRow: Int) {

    for task in taskMgr.tasks {

        if task.timerOn == true {

        //calculate the time to display in 0:00:00 format.
        let date1 : NSDate = task.timerFinishDate
        let date2 : NSDate = NSDate()
        let compareResult = date1.compare(date2)
        let length = Int(round(date1.timeIntervalSinceDate(date2)))

        var tmpHours = length / 3600
        var tmpMinutes = (length % 3600) / 60
        var tmpSeconds = length % 60

        var timeString = "\(tmpHours):\(tmpMinutes):\(tmpSeconds)"

        println(task.subText) //test, display old value before update - WORKS

        taskMgr.updateTask(indexPathRow, name: taskMgr.tasks[indexPathRow].name, subText: timeString, timerOn: taskMgr.tasks[indexPathRow].timerOn, completed: taskMgr.tasks[indexPathRow].completed, timerFinishDate: taskMgr.tasks[indexPathRow].timerFinishDate, taskID: taskMgr.tasks[indexPathRow].taskID, sliderHours: taskMgr.tasks[indexPathRow].sliderHours, sliderMinutes:taskMgr.tasks[indexPathRow].sliderMinutes, sliderSeconds: taskMgr.tasks[indexPathRow].sliderSeconds)

            println(task.subText) //test, display updated value after update - WORKS
            println(timeString) //test, display time remaining in timer 0:00:00 - WORKS
        self.tableView.reloadData() // DOES NOT UPDATE TABLE.



NSTimer selector code in TimersManager.swift:

    func tickTock (length:NSTimer!) {

    var count = 0
    for timer in timers {

                let date1 : NSDate = timer.fireDate
                let date2 : NSDate = NSDate()
                let compareResult = date1.compare(date2)
                let length = Int(round(date1.timeIntervalSinceDate(date2)))

                if length <= 0 {
                        //Invalidate NSTimer
                        //Remove from array
        println(length) //test, shows how many seconds are left - WORKS

        //update labels.
       prepMgr.update(timer.indexPathRow) //Call to listTableViewController func - Half working, calls the function. updates the correct task. But table is not reloaded.


    //update labels, reload table
    prepMgr.tableView.reloadData() //Test, Not working



source to share

1 answer

You can also use NSNotification to handle the table reload function. And just call them if you need to update the table.



All Articles