开发者

Remove the "Dismiss keybard" key from a UITextView's keyboard on iPad

I have a modal view that with a UITextView, and the user can enter some text (or not) and close the modal view. There is no point of d开发者_运维技巧ismissing the keyboard as it does not dismiss the modal view (this is on purpose), and the UITextView without the keyboard just looks silly.

Is there a way to hide or remove the "Dismiss keyboard" key from the keyboard?


You can't hide or remove the key, but you can disable it using the UITextViewDelegate protocol:

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {

    return NO;
}

If UIKit forces the responder to resign despite the delegate (doubtful, but I haven't looked closely at the call stack), you can force the keyboard to stay up by observing the UIKeyboardDidHideNotification and setting the first responder back to the UITextView: [myUITextView becomeFirstResponder]


Protocol method doesn't help. As Answerbot suggested one should listen to keyboard notification.

   - (void)onIpadViewWillAppear
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showIpadKeyboard) name:UIKeyboardDidHideNotification object:nil];
}

- (void)onIpadViewWillDisappear
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)showIpadKeyboard
{
    [myTextField becomeFirstResponder];
}

This works and looks beautifully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜