Reputation: 2281
I have a Tableview displaying data from a core DB. When a row is selected I pass information to a view controller (vc) in func prepareForSugue.
Problem is the vc I pass this information to is a child of a Tab Bar controller, and by making a segue directly to the vc I bypass this Tab Bar controller, this in turn results in the absence of a tab bar in the vc.
My question is there anyway to pass data from a tableview to the fist child of a tab bar controller and ensure the Tab Bar hierarchy is maintained?
Any input appreciated.
Tableview prepare for segue:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if(segue.identifier == "ItemDetailsSegue"){
//initilise new vc and cast as history view controller
var viewcontroller = segue.destinationViewController as History;
// pass the caseNumber we got from didselectRow to History property / instance var
println("Passing case Number to Hisory: \(caseNumberToPAsstoHistory)");
viewcontroller.caseNumberSelected = caseNumberToPAsstoHistory;
}
}
Upvotes: 1
Views: 1100
Reputation: 2281
After luk2302 advice I instantiated tabBar controllers first child from its array of view controllers and passed the data :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "ItemDetailsSegue"){
var tabBarCOntroller : UITabBarController = segue.destinationViewController as UITabBarController;
var destinationViewController_History : History = tabBarCOntroller.viewControllers?.first as History;
// Set the case number selected property of History vc
destinationViewController_History.caseNumberSelected = caseNumberToPAsstoHistory;
println("Passing case Number to Hisory: \(caseNumberToPAsstoHistory)");
}
}
Thanks for the advice :)
Upvotes: 1