操作方法是:UITableView方法和等效的UITableViewDatasource方法有什么区别?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
不同:
func cellForRow(at indexPath: IndexPath) -> UITableViewCell?
最近我遇到了我在那里延伸UITableView
能够通过排在一个给定的部分进行迭代的错误。
func forRows(inSection section: Int, condition: (UITableViewCell) ->()) {
for row in 0..<numberOfRows(inSection: section) {
let cell = cellForRow(at: IndexPath(row: row, section: section))!
condition(cell)
}
}
^^^不起作用,细胞是最后一排
func forRows(inSection section: Int, condition: (UITableViewCell) ->()) {
for row in 0..<dataSource!.tableView(self, numberOfRowsInSection: section) {
let cell = dataSource!.tableView(self, cellForRowAt: IndexPath(row: row, section: section))
condition(cell)
}
}
^^^适用于零。我明白了,但我不明白。
TableView委托方法和tableView本身的等价方法在内部有什么不同?
而'UITableView cellForRow(at:)'调用返回的单元格是通过调用其数据源上的'tableView(_:cellForRowAt:)'获得的表视图的单元格。 – rmaddy
感谢您的澄清,在问题中搞砸了,纠正它以反映这一点。 –