[英]How many times the function numberOfSections is called in tableView?
I have some simple code: 我有一些简单的代码:
class TestTableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
print("toto")
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
cell.textLabel?.text = "Hello world"
return cell
}
}
I was thinking, the function numberOfSections
was called only once, when the tableView is loading or when we ask for reload. 我当时在想,当tableView正在加载或当我们要求重新加载时,函数
numberOfSections
仅被调用一次。
But in my console with this code I have 6 "toto". 但是在带有此代码的控制台中,我有6个“ toto”。
Can someone explain to me when they enter in the function numberOfSections
? 有人在输入
numberOfSections
函数时可以向我解释吗?
numberOfSections gets called before loading the tableview. 在加载表视图之前,将调用numberOfSections。 but i also gets called when you reloadData or delete or insert or update sections and cells.
但是当您reloadData或删除或插入或更新节和单元格时,也会被调用。 the code you provided is not enough to tell what is causing numberOfSections get called 6 times
您提供的代码不足以判断是什么原因导致numberOfSections被调用6次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.