2016-06-23 12 views
0

私は選択されたUITableviewCell学生セルの情報を、情報の各部分(名、姓など)についてUITextFieldのビューコントローラにプッシュしようとしています。変更されましたが、辞書から各テキストフィールドにその情報をプッシュする方法を見つけることができません。私は不運でそれを再割り当てしようとしました。ここで辞書からUITextField(Swift)への情報のプッシュ

は私の辞書迅速ファイルの私のサンプル

class ClassRosterModel { 

//Student Dictionary for Student infomation 
var studentsRoster = [Dictionary<String, String>]() 

init() { 

    studentsRoster.append(["firstName": "Alex" , "lastName" : "Kaz", "major" : "SE", "email" : "[email protected]", "currentTerm" : "Spring", "numberOfCredits" : "\(randomCredits[0])", "password" : "000000"]) 

} 

そして、ここではセグエ

class ClassRosterTableViewController: UITableViewController { 

//declaring studentsList dictionary 
var studentsList = [Dictionary<String, String>]() 

var selectedRowIndex = 0 



    //Assignment of studentsList and myStudentRoster 
    let myStudentRoster = ClassRosterModel() 
    studentsList = myStudentRoster.studentsRoster 



//declaring cell with identifier from studentCell. 
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("studentCell", forIndexPath: indexPath) 

    // Configuring the cell with student information 
    cell.textLabel?.text = "\(studentsList[indexPath.row]["lastName"]!), \(studentsList[indexPath.row]["firstName"]!) - \(studentsList[indexPath.row]["email"]!)" 
    cell.detailTextLabel?.text = "\(studentsList[indexPath.row]["currentTerm"]!) - \(studentsList[indexPath.row]["numberOfCredits"]!) credits" 


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

    let dvc = segue.destinationViewController as! StudentInfoViewController 

    let selectedStudent = studentsList[selectedRowIndex] 

    dvc.studentRecord = selectedStudent 

} 

そして私と を選択する前に、すべてのセルを持っている私のクラスの一部であります 学生情報ページの最初のテキストフィールドを作成しました

class StudentInfoViewController: UIViewController { 

@IBOutlet weak var FirstNameTextField: UITextField! 

var studentRecord = Dictionary<String, String>() 


override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

答えて

0

これはすべてあなたのプロパティーのタイプが間違っているためですstudentsListstudentsListを、辞書のリストを格納する配列に変更する必要があります。

はまた、以下のこのコードは、私はあなたがここで何をしているか分からない

//Assignment of studentsList and myStudentRoster 
let myStudentRoster = ClassRosterModel() 
studentsList = myStudentRoster.studentsRoster 

完全に間違っています。しかし、辞書を配列に割り当てることはできません。

関連する問題