Setting a property in a segue with Navigation Controller containing another view Setting a property in a segue with Navigation Controller containing another view ios ios

Setting a property in a segue with Navigation Controller containing another view


Since the destination view controller is actually the navigation controller, try accessing the root view like so:

UINavigationController *navController = [segue destinationViewController];ShowItemsTableViewController *SITViewController = (ShowItemsTableViewController *)([navController viewControllers][0]);[SITViewController setItems:[self itemsFromCoreData]];


For Swift:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {    if segue.identifier == "segueShowNavigation" {        var DestViewController = segue.destinationViewController as! UINavigationController        let targetController = DestViewController.topViewController as! ReceiveViewController    }}


Get the topViewController from the UINavigationController:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    if ([[segue identifier] isEqualToString:@"showItems"]) {        UINavigationController *navigationController = segue.destinationViewController;        ShowItemsTableViewController *showItemsTVC = (ShowItemsTableViewController * )navigationController.topViewController;        showItemsTVC.items = [self itemsFromCoreData];    }}


matomo