У меня есть segue, который называется progmatically на performSegueWithIdentifier:
, но он не запускается. Однако, когда я создаю segue кнопкой, нажмите кнопку segue без проблем. Я также попытался изменить имя моего segue в коде, и он вызывает ошибку no segue with identifier
.Segue не выполняется Progmatically
Вот мой код (Примечание: переход называется в двух разных местах, чтобы проверить, если он будет работать где-то в коде.)
#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
вызывается и Ведение журнала.
Благодарим за помощь!
Ваша ошибка, потому что вы не назвали идентификатор segue в IB. См. [ЗДЕСЬ] (http://stackoverflow.com/questions/25020866/receiver-has-no-segue-with-identifier-when-identifier-exists), и если у вас есть идентификатор, то вы можете создать экземпляр VC – soulshined