如果在创建tableView Cell时不指定indexPath,会发生什么情况? cellForRowAt()

时间:2020-10-08 00:12:53

标签: ios swift uitableview

我很好奇,如果创建for: indexPath时不包括UITableViewCell,会发生什么事情还是不好?例如,以下是从基本UITableViewController提取的单元格的标准创建:

let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
        

我很好奇,创建这样的单元格是否会带来负面影响:

let cellWithoutIndexPath = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier")

1 个答案:

答案 0 :(得分:0)

据我所知,如果不包括indexPath,则该单元将无法知道下一步要做什么或要做什么。 “ IndexPath”的文档描述为:

“索引列表,一起表示嵌套数组树中特定位置的路径。”

如果我有一个水果数组,我想用[apple,orange,pear]填充tableView,则'indexPath.row'会指出第一个单元格应位于数组的位置0,而第二个单元格应位于位置1等。

另一个例子是这一行代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

如果我没有包括indexPath,tableView将不知道我要取消选择哪个单元格。

相关问题