2016-10-10 3 views
1

오류가하자 selectedStudent 라인에 발생하는되는 곳입니다, 내가 studentsSorted 및 studentArray를 선언 할 경우 다음 스레드 1 :. EXC_BAD_INSTRUCTION (코드 = EXC_I386_INVOP 오류 .. 정말 확실하지 왜

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 
     } 
    } 

} 

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

스레드 1 : EXC_BAD_INSTRUCTION

콘솔 로그에이 오류 거의 인쇄 오류가 발생했습니다. 이 오류는 범위를 벗어난 오류로 인해 발생할 수 있습니다. 당신이 indexPath에 self.tableView.indexPathForSelectedRow을 declear하고 성공하면

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

는, 당신은 indexPath.rowstudentsSorted의 크기로 위나 아래 고려한다.

+0

그래, studentsSorted 배열에 아무것도 없다는 것을 알았지 만 그 이유를 알 수 없습니다. – Grady

+0

'studentsSorted'에 데이터를 삽입하는 함수에 대한 정보는 없습니다. 난 그냥 교체 및 정렬'updateStudentInfo'를 찾을 수 있습니다. – NEWBIE

+0

'studentsSorted'에 데이터를 삽입하는 방법을 보여줄 수 있습니까? – NEWBIE

관련 문제