UITableView - множественный выбор - могу ли я изменить заголовок в зависимости от количества выбранных ячеек? - PullRequest
0 голосов
/ 19 февраля 2019

У меня есть обычный контроллер вида, который содержит один tableview объект.Я расширил viewcontroller для использования UITableViewDataSource, а UITableViewDelegate

My tableview допускает множественный выбор, и я могу отслеживать количество строк, выбранных с помощью tableView.indexPathsForSelectedRows.count в методе willSelectRowAt()

Я устанавливаю заголовок tableview в методе viewForHeaderInSection().Однако не существует способа связать их, чтобы сделать заголовок зависимым от количества выбранных строк

Например

Если tableView.indexPathsForSelectedRows.count <1, title = Hello</p>

Если tableView.indexPathsForSelectedRows.count = 2, title = Доброе утро

и т. Д.

Спасибо

1 Ответ

0 голосов
/ 19 февраля 2019

Вам нужно реализовать с правильным представлением

func tableView(_ tableView: UITableView, 
   viewForHeaderInSection section: Int) -> UIView? { --- }

func tableView(_ tableView: UITableView, 
    willSelectRowAt indexPath: IndexPath) -> IndexPath? {
    if let header = tableview.headerView(forSection:indexPath.section) as? YourCustomHeader {
       // here update the model with the new header name to avoid dequeuing problems 
       header.yourLbl.text = "" // change here according to any logic
    }
}

--- С titleForHeaderAt

if let header = tableview.headerView(forSection:indexPath.section) {
       // here update the model with the new header name to avoid dequeuing problems 
       header.textLabel.text = "" // change here according to any logic
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...