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.
But in my console with this code I have 6 "toto".
Can someone explain to me when they enter in the function numberOfSections
?
numberOfSections gets called before loading the tableview. but i also gets called when you reloadData or delete or insert or update sections and cells. the code you provided is not enough to tell what is causing numberOfSections get called 6 times
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.