Ios 未以编程方式执行Segue

Ios 未以编程方式执行Segue,ios,objective-c,segue,Ios,Objective C,Segue,我有一个segue被performsguewithidentifier:以编程方式调用,但它不会触发。但是,当我用按钮创建segue时,segue可以正常工作。我还尝试在代码中更改segue的名称,它会生成一个带有标识符的无segue错误 这是我的代码(注意:segue在两个不同的地方被调用,以检查它是否在代码中的其他地方工作。) 更新说明:正在调用并记录prepareforsgue方法 谢谢你的帮助 您不应该在viewDidLoad中调用performsguewithidentifier。事实

我有一个segue被
performsguewithidentifier:
以编程方式调用,但它不会触发。但是,当我用按钮创建segue时,segue可以正常工作。我还尝试在代码中更改segue的名称,它会生成一个带有标识符的
无segue
错误

这是我的代码(注意:segue在两个不同的地方被调用,以检查它是否在代码中的其他地方工作。)

更新说明:正在调用并记录
prepareforsgue
方法


谢谢你的帮助

您不应该在
viewDidLoad
中调用
performsguewithidentifier
。事实上,如果您这样做,我很肯定您会在控制台中看到警告或错误。改为将调用移动到视图显示。

对我有效的解决方案是删除有关视图控制器的所有分段,然后重新添加它们。这并不适用于所有人,但值得一试。

此外,从背景块调用它是一个糟糕的想法。这不是一个可行的选择,因为OP希望它基于IBAction完成。每次VC出现屏幕时,您的建议都会强制执行segue。这不是一件好事。OP说他们只是把它放在那里看看它是否有效。它在IBAction中不起作用。它只在我在storybaord中创建segue from按钮到view控制器时起作用(不将其连接到iAction)。编辑:而且我在控制台中没有收到任何错误。正在调用prepareForSegue方法。您是否在情节提要中实际设置了segue的标识符?单击SeGeUE中间的图标,并在检查器中输入标识符的PrimeLeic。还要确保从视图控制器本身创建segue,而不是从按钮创建segue。是的,我已经完成了所有这些事情,但仍然没有注意到。如果我将NSLog语句放在segue调用上方,它几乎会立即在调试器中显示。您会收到错误,因为您没有在IB中命名segue标识符。请参阅,如果您有命名的标识符,则可以实例化VC
#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