我有一个变量用于存储我加载到UITableView中的自定义类的对象。
我给用户提供了清除所有对象的选项。当运行此选项时,我会清除存储所有玩家的数组,但如何清除TableView?
我尝试过tableView.reloadData(),但它没有做任何事情。
自定义类和全局变量:
var players: [AnyObject] = []
Class Player{
var playerName: String?
init(name:String){
playerName = name
}
}
自定义单元格的cellForRowAtIndexPath:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: CustomMainCell = tableView.dequeueReusableCellWithIdentifier("CustomMainCell") as CustomMainCell
// Get Player
let thisPlayer:Player = players[indexPath.row] as Player
cell.nameLabel?.text = thisPlayer.playerName
}
return cell
}
清除设置功能:
alertController.addAction(UIAlertAction(title: "Clear Players?", style: .Default, handler: { (action: UIAlertAction!) in
players.removeAll()
self.tableView.reloadData()
}))
tableView.reloadData()
的调用是否在主线程/队列上执行? - The Nomad