How to push segue through a button from one view controller to another?

I am new to Objective C and I was trying to make a Segue with a button from one view controller to another. I want to use a push type for a segue with which the first view controller is embedded in the navigation view controller. Below are the .m and .h files of the first view controller.

firstViewController.m

@implementation

**(am I supposed to have an IBAction here for the pressed button?)**

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"firstSegue"]) {

    **( I don't know what to put here)**    

    }
}
@end

      

firstViewController.h

@interface firstViewController : UIViewController



@end

      

+3


source to share


1 answer


If you hooked up the button itself to the segue (ctrl + drag the button to the second view controller in the interface builder), you don't need IBAction. As long as your view controller is properly linked to the navigation controller, just hooking up to it in this way should be sufficient to make the animation push from the first view controller to the second - you don't have to write any code for everything.



The purpose of the method prepareForSegue

is to pass data to the target view controller, set up a delegate, etc. If you don't have the data to navigate to the second view controller, or you don't need to configure anything in that controller, then you don't need to implement prepareForSegue

. You can search the web for terms like segue delegate to storyboard to find some tutrorials like this that describe some usage guidelines prepareForSegue

and other storyboard features to control transitions between your view controllers.

+5


source







All Articles