0

我从应用程序委托设置了一个登录屏幕,如下所示:

  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

问题是什么?我如何解决它?

4

1 回答 1

1

是的,很明显,您的代码中有递归。在每个 viewDidAppear 中,您调用另一个 viewDidAppear。代替:

[self viewDidAppear:animated];

称呼:

[super viewDidAppear:animated];
于 2012-11-03T19:58:14.997 回答