0

I can be consider as a newbie in iOS app,

Now I have a little problem here, in my code i added [myTextView becomeFirstResponder] because I want the keyboard to be fixed on the screen. I happen to have an actionSheet on the same screen, I noticed that every time I call the action sheet to dismiss, the keyboard also dismisses without me having to call [myTextView resignFirstResponder]. This is annoying because when I dismiss the action sheet, I don't really want to dismiss the keyboard with it, I want the keyboard to remain on screen.

Somebody please explain this to me, and if you know some solution, I will be glad if you will help.

Thanks!

caribbean
  • 748
  • 1
  • 9
  • 29

2 Answers2

0

Strange, I've seen that, if iOS needs to hide UIKeyBoard reason of showing UIActionSheet or something, then it'll reshow the UIKeyBoard back, you can do two things for test,

1) Look for [myTextView resignFirstResponder] and put break point there,

2) If you implemented UITextView delegate, - (void)textViewDidEndEditing:(UITextView *)textView put the break point there too.

3) If you find your cursor goes into breakpoint when UIActionSheet dismissed then you've to correct the flow which hiding it.

If you still can't figure out, you can reshow UIKeyBoard, when UIActionSheet dismissed, with [myTextView becomeFirstResponder].

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • I don't have `[myTextView resignFirstResponder]` in my code same as `- (void)textViewDidEndEditing:(UITextView *)textView`, I have nowhere in my code that calls to dismiss the keyboard, I only call to dismiss the `actionsheet` in which I noticed that when I do so, the keyboard also dismisses itself with the action sheet – caribbean Oct 16 '13 at 07:30
  • This should not happen, which iOS version you're working on? – Hemang Oct 16 '13 at 07:31
  • both ios 6 and 7 in my case – caribbean Oct 21 '13 at 03:03
0

You can use private local category in .m file of the controller

@interface UIActionSheet (NonFirstResponder)
@end

@implementation UIActionSheet (NonFirstResponder)
- (BOOL)canBecomeFirstResponder
{
    return NO;
}
@end

It will save your keyboard on action sheet presenting. But when you try to close action sheet it will cause the chain of system calls ending with

[NSNotificationCenter postNotificationName:object:userInfo:]
[UIInputViewTransition postNotificationForTransitionStart]

Here we get UIKeyboardWillHideNotification and keyboard is closed by the system.

So you can only mark your textView as first responder on action sheet button click. But it may cause some extra UI transitions.

malex
  • 9,874
  • 3
  • 56
  • 77