Я знаю, "если indexPath.section == x или indexPath.row == x {", чтобы активировать кнопку в определенной строке.
Если моя ячейка находится в строке 5 раздела 0, что это заправильный способ записи для активации действия в этой ячейке?
Редактировать (подробнее код)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
let name = twoDimensionalArray[indexPath.section][indexPath.row]
cell.textLabel?.text = name
cell.textLabel?.text = "\(name) Section:\(indexPath.section) Row:\(indexPath.row)"
cell.accessoryType = .disclosureIndicator
return cell
}
потому что я использовал disclosureIndicator, я мог видеть раздел # & row # всех моих TableCells.
В моем разделе 5 есть только одна строка "Выход", поэтому у меня было:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if indexPath.section == 5 {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Log Out", style: .destructive, handler: { (_) in
do {
//... ...//
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
}
}
Однако в других моих разделах есть несколько строк.Итак, что я должен написать, если я хочу выполнить действие в Разделе 4, Строка 2?