Все привет! Имею tableView, в которой есть кастомные ячейки в ячейке есть кнопка, при нажатии на кнопку происходит переход в другой tabelView, но вместе с этим во второй tabelView нужно передать индекс ячейки из которой была нажата кнопка.
Погуглив сделал так:
В TableViewCell добавил
@IBOutlet weak var editButton: UIButton!
В TableViewController
var index = 0
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: “Cell”, for: indexPath) as! MainTableViewCell
cell.editButton.tag = indexPath.row cell.editButton.addTarget(self,action:#selector(buttonClicked(sender:)), for: .touchUpInside) return cell }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == “editSegue”) {
let vc = segue.destination as! AddTableViewController vc.indexToEdit = index print(index) } }
При помощи print я выяснил что при переходе (из второй ячейки, у нее индекс 1) передается почему-то 2 значения index, сначала 0, потом 1 и соответственной 2 таблица открывается 2 раза.
В чем моя ошибка?