[英]Segue Not Being Performed Progmatically
I have a segue that is being called progmatically by performSegueWithIdentifier:
but it will not trigger. 我有一个segue由
performSegueWithIdentifier:
进行编程调用performSegueWithIdentifier:
但不会触发。 However, when I create the segue with a button press the segue works without a problem. 但是,当我使用按钮创建segue时,segue可以正常工作。 I have also tried changing the name of my segue in code, and it produces a
no segue with identifier
error. 我还尝试过在代码中更改我的segue的名称,这会产生
no segue with identifier
错误的no segue with identifier
。
Here is my code (Note: the segue is called in two different places to check if it would work somewhere else in the code.) 这是我的代码(注意: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
Update for clarification: The prepareForSegue
method is being called and logging. 更新说明:调用
prepareForSegue
方法并进行日志记录。
Thanks for your help! 谢谢你的帮助!
You shouldn't call performSegueWithIdentifier
in viewDidLoad
. 您不应在
viewDidLoad
调用performSegueWithIdentifier
。 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. 而是将调用移至
viewDidAppear
。
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.
这可能并不适合所有人,但值得一试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.