2012-04-23 37 views
0

我沒有調用「[sender resignFirstResponder]」方法,但按下完成按鈕時我的鍵盤仍然關閉。我需要它保持開放,即使點擊完成。我怎麼能這樣做呢?iOS UITextField將鍵盤保持在屏幕上

這裏是我的行動,控制鍵盤:

- (IBAction)returnKeyButton:(id)sender { 

BOOL guessCorrect = [gameModel checkGuess:guessTextField.text]; 

guessTextField.text = @""; 

if (guessCorrect) { 
    CFBundleRef mainBundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileURLRef; 
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"rightAnswer", CFSTR ("mp3"), NULL); 


    UInt32 soundID; 
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 
    if (gameModel.score == 10) { 
     CFBundleRef mainBundle = CFBundleGetMainBundle(); 
     CFURLRef soundFileURLRef; 
     soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"win", CFSTR ("mp3"), NULL); 


     UInt32 soundID; 
     AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
     AudioServicesPlaySystemSound(soundID); 

     [self endGameWithMessage:@"You win!"]; 
    } else { 
     scrambledWord.text = [gameModel getScrambledWord]; 
    } 

} 
remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time]; 
playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score]; 
} 
+0

我很好奇......爲什麼? – citruspi 2012-04-23 21:54:36

+0

問題是,你猜這個問題的答案。現在,我可以通過使用「返回」鍵來猜測答案,但每當我按下它時,鍵盤都會關閉。每次我想輸入答案時都不得不再次按下文本字段,這很讓人煩惱。 – 2012-04-23 21:56:14

+0

給我幾分鐘...我有一個想法:) – citruspi 2012-04-23 21:59:54

回答

0

的...首先說實話,我從來沒有過,你有問題。我一直用辭職調用關閉鍵盤或將繼續開放。但是,這是我用你:

-(IBAction) textFieldDoneEditing : (id) sender; 

1).h文件將這個

2).m文件將這個:

-(IBAction) textFieldDoneEditing : (id) sender{ 
    [sender resignFirstResponder]; 
    [sender becomeFirstResponder]; 
} 

3)右鍵點擊的UITextField故事板,並設置發送的事件「編輯真的結束」在視圖控制器的textFieldDoneEditing方法。

現在,只要用戶按下「返回」或「完成」,鍵盤就會瞬間打開和關閉。希望能幫助到你! :)

如果它不工作,看我的Xcode項目(不工作)... download it here