2012-11-03 141 views
0

我有一個登錄界面,從應用程序的委託建立這樣的:登錄屏幕IOS5凍結

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

問題是什麼?我如何解決它?

回答

1

是的,它的問題是,你的代碼中有遞歸。在每個viewDidAppear你調用另一個viewDidAppear。 相反的:

[self viewDidAppear:animated]; 

電話:

[super viewDidAppear:animated]; 
+0

還有一個問題...文本字段變得像我上面那樣顯示視圖後,才第一個響應者。當我使用順着接下去到這個視圖的鍵盤不顯示 – user1028028