Reputation: 174
This is where the error is occuring, on the let selectedStudent line,
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
}
}
}
Here is where I declare studentsSorted and 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()
}
and this is where I declare selectedStudent,
class StudentInfoTableViewController: UITableViewController, UITextFieldDelegate {
var selectedStudent: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var delegate: studentUpdate?
Really confused here, I'd appreciate if someone could help me.
Upvotes: 1
Views: 89
Reputation: 17
Thread 1:EXC_BAD_INSTRUCTION
This error almost print error into console log. I know this error can occurred by out of range error.
if let indexPath = self.tableView.indexPathForSelectedRow {
let selectedStudent = studentsSorted[indexPath.row]
let destination = segue.destinationViewController as! StudentInfoTableViewController
destination.selectedStudent = selectedStudent
}
If you declear self.tableView.indexPathForSelectedRow to indexPath and it succeed, then you consider indexPath.row is over or under at studentsSorted's size.
Upvotes: 1