将detailView交换为其他视图时,tableView中出现错误

时间:2018-07-24 23:21:57

标签: swift function uitableview view segue

我有功能

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let indexPath = tableView.indexPathForSelectedRow {
        let object = dailyAgenda[indexPath.row]
        if object == "Time Management" {
            self.performSegue(withIdentifier: "showTimeManagement", sender: self)
        }
        else {
            self.performSegue(withIdentifier: "showDetail", sender: self)
        }}}

还有segue功能的准备

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showDetail" {
        if let indexPath = tableView.indexPathForSelectedRow {
            let object = dailyAgenda[indexPath.row]
            var controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
            controller.detailItem = object
            controller.textDescription = indepthDescript[indexPath.row]
        }}
    if segue.identifier == "showTimeManagement" {
        var controller = (segue.destination as! UINavigationController).topViewController as! TimeManagement
    }
}

但是在选择执行showTimeManagement segue的单元格时,我仍然收到错误消息“线程1:致命错误:索引超出范围”。该错误发生在showDetail segue的“ controller.textDescription = indepthDescript [indexPath.row]]”行上。为什么什至首先要运行这条线,我在哪里出错?

enter image description here

0 个答案:

没有答案