【发布时间】:2016-06-23 04:13:28
【问题描述】:
我正在尝试将信息从选定的UITableviewCell 学生单元格推送到视图控制器,其中每个信息部分(名字、姓氏等)的 UITextField 可以更改,但我不能似乎找到了如何将字典中的信息推送到每个文本字段。我试过重新分配它,但没有运气。
这是我的字典 swift 文件示例
class ClassRosterModel {
//Student Dictionary for Student infomation
var studentsRoster = [Dictionary<String, String>]()
init () {
studentsRoster.append(["firstName": "Alex" , "lastName" : "Kaz", "major" : "SE", "email" : "s123456@school.edu", "currentTerm" : "Spring", "numberOfCredits" : "\(randomCredits[0])", "password" : "000000"])
}
这是我班级的一部分,在选择之前有所有单元格 与segue
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.
}
【问题讨论】:
标签: swift uitableview dictionary uitextfield