Ios 为什么不能快速重新加载tableView?

Ios 为什么不能快速重新加载tableView?,ios,swift,uitableview,delegates,reloaddata,Ios,Swift,Uitableview,Delegates,Reloaddata,当我从delegate(或viewDidLoad)调用reloadData()时,函数tableView(…cellForRowAtIndexPath:…)未被激发。当我从点击按钮调用reloadData()时,一切都正常。为什么? override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self

当我从
delegate
(或
viewDidLoad
)调用
reloadData()
时,函数
tableView(…cellForRowAtIndexPath:…)
未被激发。当我从点击按钮调用
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.reloadData()。因为viewDidLoad()只在Viewcontroller创建时调用。

这样做

extension SCSelectSubTypeVC : UITableViewDelegate, UITableViewDataSource{

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell:SCSelectSubTypeCell = self.tblView.dequeueReusableCell(withIdentifier: "SCSelectSubTypeCell") as! SCSelectSubTypeCell
    cell.confirgureCell(datasource[indexPath.row])
    return cell

}


func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 60
}
}


如果您想在每次viewController出现时重新加载表,请在ViewWillAppease()函数中调用self.tblView.reloadData()。

别忘了,UI只能在主线程中更新

可能有多种原因,计数为零,返回部分中的项目数0是否实现了“numberOfRowsForSection”数据源方法?添加与创建
UITableView
相关的代码,以及为
TableView
设置数据的位置,然后重新加载部件。添加代码以获得更好的解释