Ошибка: Неожиданный путь с нулевым индексом в _canPerformAction:forCell:sender:, этого никогда не должно происходить.

У меня есть динамический tableView с двумя ячейками-прототипами. Я использую одну из ячеек для заголовка раздела, ячейка заголовка раздела имеет свой собственный класс. Данные были занесены в эти ячейки без проблем.

Я получаю это сообщение об ошибке «Ошибка: «Неожиданный путь с нулевым индексом в _canPerformAction: forCell: sender:, этого никогда не должно происходить». во время выполнения, когда я тапаю по заголовку раздела.Кто-нибудь знает, как избавиться от этой ошибки?Заранее спасибо!

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {  
    let cell = tableView.dequeueReusableCell(withIdentifier: "MachineTableViewCell") as! MachineTableViewCell  

    if self.uptime.count == self.machines.count {  
        cell.GPUNumber.text = self.allGPUNumber[indexPath.section][indexPath.row]  
    }  

    return cell  
}  

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {  
    guard let header = tableView.dequeueReusableCell(withIdentifier: "header") as? HeaderTableViewCell  
        else {  
            return nil  
        }  

    let machine = machine[section]  
    header.name.text = machine.name + " - " + machine.ip + ":" + machine.port  
    return header  
}  

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat  
{  
    return 124  
}

person Kevin W    schedule 15.02.2018    source источник
comment
Я получаю это сообщение об ошибке во время выполнения... какое сообщение об ошибке?   -  person Patrick    schedule 15.02.2018
comment
Привет Патрик, спасибо за ваш ответ. Извините, я вставил ошибку в заголовок. Ошибка: «Неожиданный путь нулевого индекса в _canPerformAction: forCell: sender:, этого никогда не должно происходить».   -  person Kevin W    schedule 15.02.2018
comment
Отредактируйте свой пост, чтобы добавить, чтобы облегчить модераторам.   -  person Patrick    schedule 15.02.2018
comment
Сделанный. Добавил в пост :)   -  person Kevin W    schedule 15.02.2018
comment
Где взяли Select методы?   -  person tereks    schedule 15.02.2018


Ответы (1)


Сначала я тоже пропустил это, но если вы сделаете шаг назад и посмотрите на возвращаемый тип, вы почти пнете себя.

Для обычной ячейки возвращаемый тип — UITableViewCell.

Однако для заголовка это UIView.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {  
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")...
    ///
    return cell  
}  

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {  
   let header = tableView.dequeueReusableCell(withIdentifier: "header")...
   ///
   return header  
}

Поэтому вам нужно вернуть contentView.

return header.contentView
person dschlabach    schedule 29.03.2018