当我从reloadData()
(或delegate
)调用viewDidLoad
时,不会触发功能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])
}
您可以尝试这个:
首先,从代码中删除tableView.rowHeight = 60
,然后将tableView.reloadData()
添加到viewDidLoad
。
使用此功能:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 60
}
希望有帮助...
viewDidAppear()中的添加tableView.reloadData()。因为viewDidLoad()仅在创建Viewcontroller时调用。