Как удалить конкретную строку в ячейке таблицы при нажатии кнопки в Swift - PullRequest
0 голосов
/ 16 мая 2019

Я хочу удалить определенную строку, когда я нажимаю кнопку в этой ячейке.но здесь строки удаляются на основе индекса.если я нажимаю кнопку в пятой строке, но 0-я строка индекса удаляется.

, пожалуйста, помогите мне.

вот мой код:

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EmployeeTableViewCell
    //cell.empImage.image = UIImage(named: countryArray[indexPath.row])
    cell.empName.text = namesArray[indexPath.row]

    cell.cellExpendButton.tag = indexPath.row
    cell.cellExpendButton.addTarget(self, action: #selector(expandcollapseButtonClicked), for: .touchUpInside)
    cell.removeRowButton.addTarget(self, action: #selector(removerowButtonClicked), for: .touchUpInside)

    return cell
} 

@objc func removerowButtonClicked(sender : UIButton!) {
    namesArray.remove(at: sender.tag)
    self.tableView.reloadData()
}

Я хочу удалить ячейкув какую кнопку я нажал.

1 Ответ

2 голосов
/ 16 мая 2019

Установите removeRowButton.tag на indexPath.row, теперь вы устанавливаете cell.cellExpendButton.tag = indexPath.row, по умолчанию тег любого компонента 0

cell.removeRowButton.tag = indexPath.row 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...