Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I segue between view controllers?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

How do you set a segue identifier in a storyboard?

Assigning an identifier for the segue:Select the segue, from the attribute inspector you'll see "Identifier" text field, that's it! make sure to insert the exact same name that used in performSegueWithIdentifier .


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