简体   繁体   中英

Passing data from Tableview to child of a tabbar controller

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;
        }
    }

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM