UITableView с несколькими разделами и пользовательским заголовком раздела с выбором одной ячейки и выбором нескольких ячеек - PullRequest
1 голос
/ 13 июня 2019

Я устанавливаю UITableView с несколькими разделами, а в разделе один есть один выбор, а в разделе два - несколько вариантов выбора. Он хочет именно то, что происходит в UberEats при выборе дополнений и типа пищи

Я сделал расширение и закрытие строк ячеек и хочу обновить метки в настраиваемом заголовке

var selectedIndexPath: IndexPath?

В cellForRowAt

if let inxPath = selectedIndexPath{
            if inxPath.section == 0{
                if inxPath == indexPath{
                    if inxPath.row == indexPath.row && inxPath.section == indexPath.section{
                        cell.radioButtonImageView.image = #imageLiteral(resourceName: "radioCheck")
                    }
                }
            }
            if inxPath.section == 1{
                if inxPath.row == indexPath.row && inxPath.section == indexPath.section{
                    if cell.radioButtonImageView.image == #imageLiteral(resourceName: "IconUnmarked"){
                        cell.radioButtonImageView.image = #imageLiteral(resourceName: "IconMarked")
                    }else if cell.radioButtonImageView.image == #imageLiteral(resourceName: "IconMarked"){
                        cell.radioButtonImageView.image = #imageLiteral(resourceName: "IconUnmarked")
                    }
                }

            }

        }

В didSelectRowAt

selectedIndexPath = indexPath
tableView.reloadData()

1 Ответ

1 голос
/ 13 июня 2019

Создает int и массив свойств экземпляра int для хранения выбранных деталей строки.

var selectedOfferIndex: Int? // section 0
var selectedItemIndices: [Int] = []//section 1

В cellForRow при сравнении выбранных значений и изменении пользовательского интерфейса

if section == 0 {
    if indexPath.row == selectedOfferIndex {
        //...
    } else {
        //...
    }
} else {//section 1
    if selectedItemIndices.contains(indexPath.item) {
        //...
    } else {
        //...
    }
}

В методе didSelectRowAt обновлять выбранные значения

if section == 0 {
    selectedOfferIndex = indexPath.row
} else {//section 1
    if index = selectedItemIndices.firstIndex(of: indexPath.row) {
        selectedItemIndices.remove(at: index)
    } else {
        selectedItemIndices.append(indexPath.row)
    }
}
tableView.reloadData()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...