在Swift中将String Identifier设置为Cell



我有一个接收字符串标识符数组的TableView,我需要做的是为我拥有的每个单元格设置一个标识符,并将其关联到一个名为"的变量;cellPressedId";,但当我这样做的时候,我只得到数组的最后一个值

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let selectedCell = tableView.cellForRow(at: indexPath) {
if let selectedCell = tableView.cellForRow(at: indexPath) {
var cellPressed = self.cellPressedId
}
}

我需要做的是将这个标识符设置为每个单元格,当我按下这个单元格时,就会获得标识符

选择单元格时,您可以通过此函数访问所选单元格的indexPath:func tableView(_tableView:UITableView,didSelectRowAt indexPath:indexPath(我相信你可以访问你的数据数组(你提到的字符串数组(,你可以访问这样的选择元素:

let selectedItem = myArray[indexPath.row]

最新更新