繁体   English   中英

Segue没有进行编程学习

[英]Segue Not Being Performed Progmatically

我有一个segue由performSegueWithIdentifier:进行编程调用performSegueWithIdentifier:但不会触发。 但是,当我使用按钮创建segue时,segue可以正常工作。 我还尝试过在代码中更改我的segue的名称,这会产生no segue with identifier错误的no segue with identifier

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

#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

更新说明:调用prepareForSegue方法并进行日志记录。

谢谢你的帮助!

您不应在viewDidLoad调用performSegueWithIdentifier 实际上,如果可以的话,我敢肯定您会在控制台中看到警告或错误。 而是将调用移至viewDidAppear

对我有用的解决方案是将所有序列删除到相关的视图控制器,然后重新添加它们。 这可能并不适合所有人,但值得一试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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