我有一个带有来自Firebase数据库的3个变量的表视图控制器。 我想将此数据传递给Details View Controller。 现在,我只有" title"(label1)从TableVC传递到Details VC。
我怎样才能将其余数据(label2和label3)传递给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()
}
}
有人可以帮助解决这一挑战吗?
答案 0 :(得分:0)
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)
}
答案 1 :(得分:0)
您实际上没有将值分配给label1
。将MondayViewController
更改为此:
class MondayViewController: UIViewController {
var mondayDetailDict: Dictionary<String, String> = Dictionary()
@IBOutlet weak var label1: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label1.text = mondayDetailDict["place"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}