我没有调用“[sender resignFirstResponder]”方法,但按下完成按钮后我的键盘仍然关闭。我需要它保持开放,即使我点击完成。我怎么能这样做呢?
这是我控制键盘的动作:
- (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 :(得分:0)
首先......说实话,我从未遇到过你的问题。我总是不得不使用辞职电话来关闭键盘,否则它会保持打开状态......但是,这就是我用过的东西:
1)把它放在.h文件中:
-(IBAction) textFieldDoneEditing : (id) sender;
2)把它放在.m文件中:
-(IBAction) textFieldDoneEditing : (id) sender{
[sender resignFirstResponder];
[sender becomeFirstResponder];
}
3)右键单击故事板中的UITextField,并将发送事件“Editing Did End”设置为视图控制器中的textFieldDoneEditing方法。
现在,只要用户按下“Return”或“Done”,键盘就会立即打开和关闭。希望能帮助到你! :)
如果它不起作用,请查看我的Xcode项目(它确实有效)...... download it here