为什么不重新加载tableView工作迅速?

问题描述 投票:0回答:2

当我从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])
}
ios swift uitableview delegates reloaddata
2个回答
0
投票

您可以尝试这个:

首先,从代码中删除tableView.rowHeight = 60,然后将tableView.reloadData()添加到viewDidLoad

使用此功能:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return 60
}

希望有帮助...


0
投票

viewDidAppear()中的添加tableView.reloadData()。因为viewDidLoad()仅在创建Viewcontroller时调用。

© www.soinside.com 2019 - 2024. All rights reserved.