我的数据有 50 个条目。模拟器12点就停了,不懂。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
funcSectCount += 1
let data = AppData.orgNames
print("data.count=", data.count, " func Section count=", funcSectCount)
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
funcRowCount += 1
let data = AppData.orgNames
let cell = myTable.dequeueReusableCell(withIdentifier: "myCell", for:
indexPath)
cell.textLabel?.text = data[indexPath.row]
print("indexPath.row=", indexPath.row, " func Row count=", funcRowCount)
return cell
}
这是每个函数的最终打印:
data.count= 50 func Section count= 3 (curious, but minor)
indexPath.row= 11 func Row count= 12
最佳答案
tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
每次需要一个新单元格时由 TableView 调用。
如果一次只有 12 个单元格可见,那么 TableView 最初只需要 12 个单元格,因此只会要求 12 个单元格。您必须滚动才能需要更多。在需要单元格之前,它不会请求单元格。
关于ios - 为什么模拟器只有12行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882496/