gpt4 book ai didi

ios - Segue 未以编程方式执行

转载 作者:行者123 更新时间:2023-12-01 18:54:03 25 4
gpt4 key购买 nike

我有一个由performSegueWithIdentifier:以编程方式调用的segue,但它不会触发。但是,当我用按钮创建 Segue 时,按下 Segue 就可以正常工作。我还尝试在代码中更改我的 segue 的名称,它会产生 no segue withidentifier 错误。

这是我的代码(注意:在两个不同的地方调用 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

关于ios - Segue 未以编程方式执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27760093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com