![](/img/trans.png)
[英]numberofSections method not getting called by [tableview reloadData]
[英]How many times the function numberOfSections is called in tableView?
我有一些簡單的代碼:
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
}
}
我當時在想,當tableView正在加載或當我們要求重新加載時,函數numberOfSections
僅被調用一次。
但是在帶有此代碼的控制台中,我有6個“ toto”。
有人在輸入numberOfSections
函數時可以向我解釋嗎?
在加載表視圖之前,將調用numberOfSections。 但是當您reloadData或刪除或插入或更新節和單元格時,也會被調用。 您提供的代碼不足以判斷是什么原因導致numberOfSections被調用6次
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.