gpt4 book ai didi

swift - 如何在 UITableViewCell 类中使用prepare for segue

转载 作者:行者123 更新时间:2023-11-30 10:36:10 24 4
gpt4 key购买 nike

我想在 UITableViewCell 和 UIViewController 之间发送数据

我有一个地址列表,在我的单元格中有一个按钮(编辑),我想发送有关单元格中地址的所有信息

@IBOutlet weak var address: UILabel!
@IBOutlet weak var rfc: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is ContainerVC{

let vc = segue.destination as? ContainerVC
vc.address = self.address.text
}
}

方法不会覆盖其父类(super class)中的任何方法

最佳答案

让我们在 Controller 中使用 segue,其中包含使用 UITableViewCell 的 tableview

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == segueIdentifier,
let destination = segue.destination as? ContainerVC,
let selectedIndex = tableView.indexPathForSelectedRow?.row
{
destination.address = self.addresses[selectedIndex].text
self.navigationController?.pushViewController(destination, animated: true) // For example
}
}

关于swift - 如何在 UITableViewCell 类中使用prepare for segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57983357/

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