Кнопка «Скрыть» в другой ячейке при нажатии - PullRequest
0 голосов
/ 21 сентября 2018

У меня есть `tableView с тремя ячейками.В двух из них у меня есть кнопка.Я хотел бы скрыть кнопку в другой ячейке, когда нажата одна из ячеек.

Я пробовал некоторые решения в didSelectRowAt, но не смог скрыть кнопки:

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 1 {
        if let cell = tableView.cellForRow(at: indexPath) as? ComposeCell1 {
           cell.compose.isHidden = true
        if let cell2 = tableView.cellForRow(at: indexPath) as? ComposeCell2 {
            cell2.compose.isHidden = true //I can reach the cell from here, but its not hiding the button
            }

            }
        } else if indexPath.row == 2 {
            if let cell = tableView.cellForRow(at: indexPath) as? ComposeCell2 {
                cell.compose.isHidden = true
            }
        }
    }

1 Ответ

0 голосов
/ 22 сентября 2018

Попробуйте отследить индекс для нажатой кнопки с помощью переменной.И используйте переменную в tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell, чтобы обновить видимость кнопки.Единственное, что вам нужно сделать в didSelectRowAt, это присвоить значение индекса переменной и перезагрузить табличное представление

var selectedIndex: Int?

....

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    selectedIndex = indexPath.row
    tableView.reloadData()
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   .....
   cell.compose.isHidden = indexPath.row != selectedIndex
   .....
   return cell

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