,可以通过以下步骤实现:
下面是一个示例代码:
// 在源ViewController中
import UIKit
class SourceViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var dataFromTableView1: Any?
var dataFromTableView2: Any?
// ...
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView == tableView1 {
dataFromTableView1 = // 获取tableView1对应行的数据
} else if tableView == tableView2 {
dataFromTableView2 = // 获取tableView2对应行的数据
}
performSegue(withIdentifier: "segueToDestination", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueToDestination" {
let destinationVC = segue.destination as! DestinationViewController
destinationVC.data1 = dataFromTableView1
destinationVC.data2 = dataFromTableView2
}
}
}
// 在目标ViewController中
import UIKit
class DestinationViewController: UIViewController {
var data1: Any?
var data2: Any?
// ...
override func viewDidLoad() {
super.viewDidLoad()
// 使用data1和data2来更新界面或进行其他操作
}
}
在这个示例中,我们通过点击表视图的某一行来获取对应的数据,并将其传递给目标ViewController。在目标ViewController中,我们使用接收到的数据来更新界面或进行其他操作。
请注意,这只是一个示例代码,实际情况中,你可能需要根据具体的业务需求进行适当的修改和调整。
领取专属 10元无门槛券
手把手带您无忧上云