线程1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP错误.不知道为什么



这就是错误发生的地方,在let selectedStudent行,

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if(segue.identifier == "Student_segue") {
        if let indexPath = self.tableView.indexPathForSelectedRow {
            let selectedStudent = studentsSorted[indexPath.row]
            let destination = segue.destinationViewController as! StudentInfoTableViewController
            destination.selectedStudent = selectedStudent
        }
    }
}

这里是我声明studentsSorted和studentArray的地方。

typealias studentInfo = Dictionary<String, AnyObject>
typealias studentArray = [studentInfo]
let students = StudentRosterModel()
var studentsSorted:studentArray = studentArray()
var selectedRow:Int = 0
func updateStudentInfo(updatedStudent: Dictionary<String, AnyObject>) {
    // replaced the selected row with the updated key/value dictionary
    studentsSorted [selectedRow ] = updatedStudent
    // sort the revised student list
    studentsSorted.sortInPlace{ ($0["last_name"] as? String) < ($1["last_name"] as? String )}
    // reload () tableView to show refreshed view
    tableView.reloadData()

}

我在这里声明selectedStudent

class StudentInfoTableViewController: UITableViewController, UITextFieldDelegate {
var selectedStudent: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var delegate: studentUpdate?

我真的很困惑,如果有人能帮助我,我将不胜感激。

线程1:EXC_BAD_INSTRUCTION

这个错误几乎打印错误到控制台日志。我知道这个错误可能是由超出范围错误引起的。

if let indexPath = self.tableView.indexPathForSelectedRow {
    let selectedStudent = studentsSorted[indexPath.row]
    let destination = segue.destinationViewController as! StudentInfoTableViewController
    destination.selectedStudent = selectedStudent
}

如果你清空self。tableview。indexPathForSelectedRow到indexPath并且它成功了,那么您考虑indexPath。row大于或小于studentsSorted的大小

最新更新