2012-04-23 119 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