I’m new to Objective C and I’ve been trying to do Segue using a button from one view controller to another. I wish to use a push type for the segue with which, the first view controller is embedded in a navigation view controller. Below is 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
If you have wired up the button itself to the segue (ctrl + drag from the button to the second view controller in the interface builder), then you will not need an IBAction. As long as your view controller is properly associated with a navigation controller, just wiring up the segue in this way should be sufficient to do a push animation from the first view controller to the second–you won’t have to write any code at all.
The purpose of the
prepareForSeguemethod is pass data to the target view controller, set up a delegate, etc. If you have no data to pass to the second view controller, or nothing to configure in that controller, then you wouldn’t need to implementprepareForSegue. You can search online for terms such as storyboard segue delegate to find some tutrorials like this that describe some best practices for usingprepareForSegueand other storyboard functionality to manage transitions between your view controllers.