【发布时间】:2017-02-20 15:18:00
【问题描述】:
我是 swift 和 IOS 的新手,将字典数据传递给其他 uiview 时遇到问题,谁能帮我解决?
LessonsTableViewController:
var mylessons = [
["title":"Posture", "subtitle":"Set up your body", "bgimage":"1", "lesimage":"l1"],
["title":"Breathing", "subtitle":"Breathing deeply", "bgimage":"2", "lesimage":"l2"],
["title":"Breathing", "subtitle":"Breathing Exercise", "bgimage":"3", "lesimage":"l3"],
["title":"Health", "subtitle":"Do’s & Don’ts", "bgimage":"4", "lesimage":"l4"]
]
和
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! LessonsTableViewCell
let lessonsObject = mylessons[indexPath.row]
cell.backgroundImageView.image = UIImage(named: lessonsObject["bgimage"]!)
cell.titleLabel.text = lessonsObject["title"]
cell.subtitleLabal.text = lessonsObject["subtitle"]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "LessonSegue", sender: mylessons[indexPath.row])
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
let lessegue = segue.destination as! LessonDetailsViewController
lessegue.SelectedLessons = mylessons
}
LessonDetailsViewController:
@IBOutlet weak var LTitle: UILabel!
var SelectedLessons = [Dictionary<String, String>()]
override func viewDidLoad() {
super.viewDidLoad()
LTitle.text = SelectedLessons["title"]
// Do any additional setup after loading the view.
}
最后,它有一个错误“Cannot subscript a value of type '[Dictionary]' with an index of 'String'.
【问题讨论】:
标签: ios swift uitableview segue