简体   繁体   中英

Segue Not Being Performed Progmatically

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM