Мой сценарий, я загрузил свои JSON
данные в tableView
с помощью codable
.Здесь я добавил свою отметку tableView
cell multiple
и отметку deselect
.Теперь, если я выбираю ячейку tableView, я могу получить cell
данные, но я хочу добавить в одну array
, то же самое, если я не выбираю ячейку. Она должна remove
из массива.Выбранные данные ячейки я перехожу на другую ViewController
.Я хотел бы знать, как это сделать.
Мой код
// method to run when table view cell is tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You tapped cell number \(indexPath.row).")
if let cell = tableView.cellForRow(at: indexPath as IndexPath) {
if cell.accessoryType == .checkmark {
cell.accessoryType = .none
} else {
cell.accessoryType = .checkmark
let item = users[indexPath.row]
print(item) // here printing cell selection data
}
}
}
Мой токовый выход выбора ячейки
You tapped cell number 1.
User(userId: "121”, active: 1, name: example_table.Name(firstname: "jack", lastname: "m"))
You tapped cell number 2.
User(userId: "122”, active: 1, name: example_table.Name(firstname: “rose”, lastname: “h”))
You tapped cell number 3.
User(userId: "123”, active: 1, name: example_table.Name(firstname: “makj”, lastname: “i”))