gpt4 book ai didi

ios - 将数据从一个 UITableView 传递到 didSelectRow 中的另一个 UITableView?

转载 作者:行者123 更新时间:2023-11-28 15:19:56 24 4
gpt4 key购买 nike

有两个 UITableView,第一个有一个单元格,点击它会打开第二个 UITableView。选择第二个 UITableView 中的单元格时,第二个 tableView 屏幕应关闭并携带该单元格中的文本,并填充第一个 UITableView 单元格标签中的标签。到目前为止,我的代码如下,它给出了线程错误:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let destVC = EnrollmentAccountTableViewController()
destVC.lblAccountType.text = GlobalParams.enrollmentAccountTypes[indexPath.row].acctName

self.navigationController?.popViewController(animated: true)
}

最佳答案

试试这个:-

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: 
IndexPath) {

for obj in (self.navigationController?.viewControllers)! {
if obj is EnrollmentAccountTableViewController {
let vc2: EnrollmentAccountTableViewController = obj as! EnrollmentAccountTableViewController
vc2.strAccname = GlobalParams.enrollmentAccountTypes[indexPath.row].acctName
_ =
self.navigationController?.popToViewController(vc2, animated: true)
break
}
}

}

在您的 EnrollmentAccountTableViewController 中

var  strAccname:String!

override func viewWillAppear(_ animated: Bool) {
if strAccname != nil {
self.lblAccountType.text = strAccname
}
}

关于ios - 将数据从一个 UITableView 传递到 didSelectRow 中的另一个 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46178377/

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