gpt4 book ai didi

ios - Swift:如何将数据从 TableViewController 传递到 Details VC

转载 作者:行者123 更新时间:2023-11-30 12:57:38 25 4
gpt4 key购买 nike

我有一个 TableView Controller ,其中包含 Firebase 数据库中的 3 个变量。我想将此数据传递给详细信息 View Controller 。目前,我只有“标题”(label1)从TableVC传递到Details VC。

如何将其余数据(标签2和标签3)传递给DetailsVC?

MondayTableVC:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("Cell_Monday")

let messageSnapshot: FIRDataSnapshot! = conf[indexPath.row]
let message = messageSnapshot.value as! Dictionary<String, String>

// print(message)

let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = message["title"]

let label2 = cell?.viewWithTag(2) as! UILabel
label2.text = message["place"]

let label3 = cell?.viewWithTag(3) as! UILabel
label3.text = message["date"]


return cell!

}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {



let messageSnapshot: FIRDataSnapshot! = conf[indexPath.row]
let message = messageSnapshot.value as! Dictionary<String, String>

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let monDetails = storyBoard.instantiateViewControllerWithIdentifier("mondayDetails") as! MondayViewController
monDetails.title = message["title"]


monDetails.mondayDetailDict = message
self.navigationController?.pushViewController(monDetails, animated: true)


}

星期一(详细信息)ViewController:

class MondayViewController: UIViewController {

var mondayDetailDict: Dictionary<String, String> = Dictionary()


@IBOutlet weak var label1: UILabel!


override func viewDidLoad() {
super.viewDidLoad()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}


}

有人可以帮助解决这个挑战吗?

最佳答案

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

let messageSnapshot: FIRDataSnapshot! = conf[indexPath.row]
let message = messageSnapshot.value as! Dictionary<String, String>

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let monDetails = storyBoard.instantiateViewControllerWithIdentifier("mondayDetails") as! MondayViewController
monDetails.title = message["title"]
let cell = tableView.cellForRow(at: indexPath) as! CellClass

let label2 = cell?.viewWithTag(2) as! UILabel
monDetails.field2 = label2.text

let label3 = cell?.viewWithTag(3) as! UILabel
monDetails.field3 = label3.text

monDetails.conferenceDetailDict = message
self.navigationController?.pushViewController(monDetails, animated: true)


}

关于ios - Swift:如何将数据从 TableViewController 传递到 Details VC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40237155/

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