我有一个用JSON填充的表。它作为日历工作。单击日期时,应使用当天的事件填充下表。
这些表在找到数据后填充表格,但只执行一次。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return(GlobalVar.TodaysEvents.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventCell", for: indexPath) as! WhitelistTableViewCell
cell.startTime.adjustsFontSizeToFitWidth = true
print(GlobalVar.TodaysEventsTimes[indexPath.row])
cell.startTime.text = (GlobalVar.TodaysEventsTimes[indexPath.row] as! String)
cell.Summary.text = GlobalVar.TodaysEvents[indexPath.row] as? String
return(cell)
}
我见过其他类似的帖子,他们使用:
self.tableView.reload()
然而,当我尝试这个时,它并没有认识到" tableView"并且根本不起作用。
任何建议都会受到赞赏,提前谢谢
答案 0 :(得分:1)
创建对tableView(New Referencing Outlet)的引用,然后执行以下操作:
yourTableView.reloadData()
答案 1 :(得分:0)
我不知道你在哪里重新加载tableview但我认为你在不同的线程重新加载表视图。这就是为什么请在数组中插入数据后重新加载表视图。