user1086279
user1086279

Reputation: 111

UINavigationController UIBarButtonItem Push Segue

When I view a UIBarButtonItem and drag from Connections Inspector the "push" segue, I can connect it to another view controller in the storyboard. When I run it and click the UIBarButtonItem the ViewController I connected up in IB magically appears.

My question is: where does this happen? This, "push" event. Is there a method in a parent ViewController? Something like: "PushSegue"? I'd like to pass information to the connected ViewController from the navigation view controller. For example, if I wanted to popup a UIAlertView at that moment, where would I do that? Somewhere in the ViewController class?

Upvotes: 0

Views: 2061

Answers (1)

Darren
Darren

Reputation: 10398

Once a segue has been called (by pressing the button) it calls prepareForSegue. In prepareForSegue you check which segue was called and then can run any code you want to prepare the next view controller.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
{
    // Get reference to the destination view controller
    YourViewController *vc = [segue destinationViewController];

    // Pass any objects to the view controller here, like...
    [vc setMyObjectHere:object];
}
}

Upvotes: 2

Related Questions