iOS storyboard passing data navigationViewController iOS storyboard passing data navigationViewController ios ios

iOS storyboard passing data navigationViewController


UINavigationController has a property called topViewController which returns the view controller that is at the top of the stack.

So your prepareForSegue: method may look something like this...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{    if ([[segue identifier] isEqualToString:@"sLogowanieFirmy"]) {        UINavigationController *nav = [segue destinationViewController];        FirmyVC *firmyVC = (FirmyVC *)nav.topViewController;        firmyVC.tabFirmy = self.tabFirmy;    }    // etc...}


Here it is in swift:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {        if (segue.identifier == "sLogowanieFirmy") {        let nav = segue.destinationViewController as! UINavigationController         let firmyVC = nav.topViewController as! FirmyVC        firmyVC.tabFirmy = self.tabFirmy                }    // etc...}