【问题标题】:iOS UITextField keep keyboard on the screeniOS UITextField 将键盘保持在屏幕上
【发布时间】:2012-04-23 21:51:24
【问题描述】:

我没有调用“[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];
}

【问题讨论】:

  • 重点是,你猜问题的答案。就目前而言,我可以通过使用“return”键来猜测答案,但是每当我按下它时,键盘就会关闭。每次我想输入答案时都必须再次按文本字段,这很烦人。
  • 给我几分钟...我有个主意:)
  • 这是一个很好的理由......从来没想过!
  • 非常感谢!我正在尝试我能想到的一切。
  • 知道了!写一个答案....

标签: ios keyboard uitextview


【解决方案1】:

首先...说实话,我从来没有遇到过你遇到的问题。我总是不得不使用 resign 调用来关闭键盘,否则它会保持打开状态......但是,这是我为你使用的:

1) 将其放入 .h 文件中:

-(IBAction) textFieldDoneEditing : (id) sender;

2) 将其放入 .m 文件中:

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

3) 右键单击​​故事板中的 UITextField 并将 Sent 事件“Editing Did End”设置为视图控制器中的 textFieldDoneEditing 方法。

现在,只要用户按下“返回”或“完成”,键盘就会立即打开和关闭。希望能帮助到你! :)

如果不起作用,请查看我的 Xcode 项目(确实有效)...download it here

【讨论】:

    猜你喜欢
    • 2012-09-25
    • 2011-03-31
    • 2019-04-13
    • 2023-03-26
    • 1970-01-01
    • 2015-04-30
    • 2013-09-22
    • 1970-01-01
    • 2014-04-26
    相关资源
    最近更新 更多