I can't figure out why my segue.identifier is always returning null. I set the segue identifiers in the storboard.
ViewController1
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"prepared %@",segue.identifier);
if([[segue identifier] isEqualToString:@"segue1"] ){
NSLog(@"segue is equal to 1");
}
}
ViewController2
- (IBAction)unwindFromSegue:(UIStoryboardSegue *)segue {
NSLog(@"unwinded %@",segue.identifier);
}
The log message is always null so if statement is never true. Any thoughts why i cant get the identifier?
EDIT:
I made a whole new project for testing. It's a single view application with ViewController and SecondViewController. In the storyboard I made a popover segue connection from a button in View Controller to SecondViewController and set the segue identifier to segue1.
On SecondViewController I made a back button and connected it to the unwindFromSegue in my ViewController. I also added prepareForSegue in the SecondViewController.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)unwindFromSegue:(UIStoryboardSegue *)segue {
NSLog(@"unwinded %@",segue.identifier);
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@end
SecondViewController.m
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)
nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//was just testing unwindFromSegue here. Didn't mean to post here,
//but I will keep it in with an answer referring to it
//- (IBAction)unwindFromSegue:(UIStoryboardSegue *)segue{
//NSLog(@"unwind in second %@",segue.identifier);
//}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"prepare %@",segue.identifier);
}
@end
Hope this helps. Thanks