2

I have a segue that is being called progmatically by performSegueWithIdentifier: but it will not trigger. However, when I create the segue with a button press the segue works without a problem. I have also tried changing the name of my segue in code, and it produces a no segue with identifier error.

Here is my code (Note: the segue is called in two different places to check if it would work somewhere else in the code.)

#import "SignUpViewController.h"
#import "ProgressHUD.h"

@interface SignUpViewController ()

@end

@implementation SignUpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self performSegueWithIdentifier:@"profilePic" sender:self];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)createAnAccount:(id)sender {

    [ProgressHUD show:@"Please Wait"];

    if ([self.passwrod.text isEqualToString:self.confirmPassword.text]){
        // Register User
        PFUser *user = [PFUser user];
        user.username = self.username.text;
        user.password = self.passwrod.text;
        user.email = self.eMail.text;

        // other fields can be set if you want to save more information

        NSString *name = [self.firstName.text stringByAppendingString:@" "];
        NSString *fullName = [name stringByAppendingString:self.lastName.text];

        user[@"name"] = fullName;

        user[@"posts"]     = @0;
        user[@"score"]     = @5;
        user[@"followers"] = @0;
        user[@"following"] = @0;

        [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (!error) {

                // Hooray! Let them use the app now.

                [self performSegueWithIdentifier:@"profilePic" sender:self];

                [ProgressHUD showSuccess:nil];
                NSLog(@"Perform Segue");

            } else {
                NSString *errorString = [error userInfo][@"error"];
                // Show the errorString somewhere and let the user try again.

                [ProgressHUD showError:errorString];
            }
        }];

    } else {
        // Alert User
        [ProgressHUD showError:@"Please check your passwords as they do not match."];
    }

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"Preparing for segue");
    NSLog(@"Segue: %@", segue.identifier);
}

@end

Update for clarification: The prepareForSegue method is being called and logging.

Thanks for your help!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
jbokwx
  • 195
  • 1
  • 2
  • 14
  • Your getting the error because you haven't named the segue identifier in IB. See [HERE](http://stackoverflow.com/questions/25020866/receiver-has-no-segue-with-identifier-when-identifier-exists) and if you have the identifier named then you can instantiate the VC – soulshined Jan 03 '15 at 22:23

2 Answers2

5

You shouldn't call performSegueWithIdentifier in viewDidLoad. In fact, I'm pretty sure you'll see a warning or error in the console if you do. Move the call to viewDidAppear instead.

stromdotcom
  • 381
  • 1
  • 8
  • Also, calling it from a background block is a bad idea – Paulw11 Jan 03 '15 at 22:19
  • This is not a viable option because the OP wants it done based off an IBAction. Your suggestion will force the segue every time the screen appears for the VC. Not a good thing. The OP stated they just put it there to see if it would work. – soulshined Jan 03 '15 at 22:21
  • It does not work in IBAction. It only works when I create the segue from button to view controller in storybaord (not hooking it up to IBAction). Edit: Also I am not getting any errors in the console. The prepareForSegue method is being called. – jbokwx Jan 03 '15 at 22:27
  • Have you actually set the identifier of the segue in storyboard? Click the icon in the middle of your segue, and enter **profilePic** in the inspector for the identifier. Also make sure you create the segue from the view controller itself, not from a button. – stromdotcom Jan 03 '15 at 22:28
  • Yes I have done all of those things, and still noting. If I place an NSLog statement above the call for the segue it shows it in the debugger almost instantly. – jbokwx Jan 03 '15 at 22:30
0

The solution that worked for me was to delete all the segues to the view controller in question and then re-added them. This porbably won't work for everyone, but it is worth a shot.

jbokwx
  • 195
  • 1
  • 2
  • 14