gpt4 book ai didi

ios - 将数据从 uitableview 传递到其他 uiview

转载 作者:行者123 更新时间:2023-11-28 06:24:42 27 4
gpt4 key购买 nike

我是 swift 和 IOS 的新手,我在将字典数据传递给其他 uiview 时遇到了一些问题,有人可以帮我解决这个问题吗?

类(class) TableView Controller :

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
}

类(class)详情 View Controller :

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

最后,它有一个错误“无法使用‘String’类型的索引为‘[Dictionary]’类型的值下标。

最佳答案

首先,您的 SelectedLessons 类型错误。你需要使用类似 tis 的东西

var SelectedLessons:Dictionary<String, String>?

而且你需要过去正确的宾语。

override func prepare(for segue: UIStoryboardSegue, sender: Any?){
let lessegue = segue.destination as! LessonDetailsViewController
lessegue.SelectedLessons = sender as? Dictionary<String,String>
}

关于ios - 将数据从 uitableview 传递到其他 uiview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com