У меня есть tableView, и я хочу обновлять его каждые 10 секунд. Для этого я:Как обновить ячейки tableView?
var timer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: "reloadTable", userInfo: nil, repeats: true)
func reloadTable() {
print("reload")
self.tableView.reloadData()
}
но он не перезагружается правильно. Что это значит:
Да, он перезагружается, но мои данные не обновляются, но когда я перетаскиваю свой tableView в верхнюю часть и оставляю его, данные ячеек таблицы table обновляются. Как я могу добиться этого эффекта программно?
UPDATE
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> onlineUserCell {
let cell:onlineUserCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! onlineUserCell
let user = OneRoster.userFromRosterAtIndexPath(indexPath: indexPath)
cell.username.text = user.displayName
if user.unreadMessages.intValue > 0 {
cell.backgroundColor = .orangeColor()
} else {
cell.backgroundColor = .whiteColor()
}
configurePhotoForCell(cell, user: user)
cell.avatarImage.layer.cornerRadius = cell.avatarImage.frame.size.height/2
cell.avatarImage.clipsToBounds = true
return cell;
}
'dispatch_async (dispatch_get_main_queue()) { self.table.reloadData() }' try this –
Как вы строите ячейку? Выделите код метода cellForRowAtIndexPath: '. – Gandalf
Я вижу. Попробуйте, что @HarvantS. предложил. Вероятно, это из-за потока, отличного от потока пользовательского интерфейса. Сохраните точку прерывания в вашем методе и посмотрите, не получаете ли вы объект обновления 'user', когда вы его обновляете. – Gandalf