我有一个从app delegate设置的登录屏幕,如下所示:
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
BOOL needsPassCheck = [def boolForKey:kHasPassword];
if (needsPassCheck) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
VerifyPasswordViewController *passC = (VerifyPasswordViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"passCheck"];
passC.loginCheck = YES;
self.window.rootViewController = passC;
}
在视图控制器中,启动方法是:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (self.loginCheck) {
[self.topBar setHidden:YES];
self.enterPLabel.text = NSLocalizedString(@"Enter Password", @"Enter Password");
}else {
[self.topBar setHidden:NO];
self.enterPLabel.text = NSLocalizedString(@"Enter Old Password", @"Enter Old Password");
}
[self.continueButton setTitle:NSLocalizedString(@"Continue", @"Continue") forState:UIControlStateNormal];
}
-(void)viewDidAppear:(BOOL)animated
{
[self.passwordTextField becomeFirstResponder];
[self viewDidAppear:animated];
}
问题在于它似乎无限循环: http://i.imgur.com/KmarG.png
有什么问题?我如何解决它?
答案 0 :(得分:1)
是的,它是obvous,你的代码中有递归。在每个viewDidAppear中,您调用另一个viewDidAppear。 而不是:
[self viewDidAppear:animated];
呼叫:
[super viewDidAppear:animated];