尝试从TimersManager.swift文件中重新加载UITableView时遇到了问题。 TimersManager.swift用于控制/管理我的待办事项列表/计时器应用程序中的所有计时器。我正在尝试更新UILabel,以便在计时器结束时显示更新的时间。由于某种原因,它不会更新表。请看下面,希望你能给我一个正确方向的推动。感谢。
listTableViewController.swift的顶部:
var prepMgr: listTableViewController = listTableViewController()
var cell:customCell!
class listTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
在listTableViewController中更新func :(这是由我的TimersManager.swift文件中的另一个func调用的)
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.
}
}
TimersManager.swift中的NSTimer选择器的代码:
func tickTock (length:NSTimer!) {
println(length.userInfo)
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
timer.myTimer.invalidate()
//Remove from array
timers.removeAtIndex(count)
}
count++
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
}
答案 0 :(得分:1)
您还可以使用NSNotification来处理表的“重新加载功能”。如果您需要更新表格,请致电他们。