【发布时间】:2020-03-09 11:09:53
【问题描述】:
当我从delegate(或viewDidLoad)调用reloadData() 时,不会触发函数tableView(...cellForRowAtIndexPath:..)。当我从 tapButton 调用 reloadData() 时,一切正常。为什么?
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
exerciseList = ExerciseListTableViewController.ExerciseList
trainingList = TrainingListTableViewController.trainingList
if UserDefaults.standard.integer(forKey: "FactoryEx") != 0 {
identifierFactory = UserDefaults.standard.integer(forKey: "FactoryEx")
}
tableView.rowHeight = 60
tableView.allowsSelection = false
//tableView.tableFooterView = UIView()
}
func reload(choose: Bool){
exerciseTableChoose = choose
tableView.reloadData()
}
@IBAction func reload(_ sender: UIButton) {
exerciseList.append(Exercise())
tableView.reloadData()
}
protocol FirstTable {
func reload(choose: Bool)
func addCell(name: String, parametr: [Bool])
}
【问题讨论】:
-
可能有多种原因,计数为零,部分中的项目数返回 0
-
你实现了'numberOfRowsForSection'数据源方法吗?
-
添加与
UITableView创建相关的代码以及为TableView设置数据的位置并重新加载部分。添加代码以获得更好的解释
标签: ios swift uitableview delegates reloaddata