Trying to pass data to an embedded table view controller. I am able to pass the data to the view controller but not the embedded table view controller. I am assuming it has something to do with child/parent relationship... just not sure on the code to use for that relationship.
Here is what I have right now. The DealDetailTableViewController is embedded in a View Controller.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "showDealDetails") {
var detailScene = segue.destinationViewController as! DealDetailTableViewController
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.dealObject = (objects?[row] as! PFObject)
}
}
答案 0 :(得分:6)
First,in the contain viewController,keep a variable
weak var embedvc:DealDetailTableViewController?
Then in prepare for segue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "showDealDetails") {
var detailScene = segue.destinationViewController as! DealDetailTableViewController
self.embedvc = detailScene;
}
}
Every time you pass data,you just need to
self.embedvc?.dealObject = ...//balabala