У меня есть табличное представление в моем приложении, оно должно отображать список сообщений чата. Я получил сообщения чата, загруженные в NSMutableArray
, и после загрузки данных в массив мне нужно обновить tableview.tableview reload метод данных, вызываемый, но не выполняющий
вот код, я использую:
dispatch_async(dispatch_get_main_queue(), {() -> Void in
("reloading data")
self.tableView.reloadData()
})
Но он печатает reloading data
, но не обновляет/перезагрузить TableView.
Любые идеи?
UPDATE
я понял, что это не вызов этого метода:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println("running")
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
println(listDataArray[indexPath.row])
cell.textLabel?.text = (listDataArray[indexPath.row] as NSString)
return cell
}
но если попытаться удалить или закомментировать, то их говорит класс не соответствует к протоколам UITableViewDataSource
.
Итак, как же это просто не вызвать метод? (NOTE: it is not printing "running" either)
UPDATE 2
вот код для tableview
методов (обратите внимание, я слегка изменили один из когда я писал выше)
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
if(listDataArray.count > 0) {
return listDataArray.count
} else {
return 0
}
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell
if !(cell != nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
}
cell?.textLabel?.text = listDataArray[indexPath.row] as? String
return cell
}
Возможно, ваш массив не обновляется, как вы думаете, или, возможно, ваш cellForRowAtIndexPath неправильно ... Это может быть несколько вещей ... –
я знаю массив обновляется, потому что, если я его распечатаю, в новом содержимом будет – Haring10
[self.tableView reloadData]; –