我的iOS应用程序中出现奇怪的键盘行为

时间:2022-01-16 17:26:56

Ok, so here's how my keyboard behaves: There's a button which calls a method to send a textmessage, that works fine. If the user now sends the text everything's fine. Now if (s)he taps cancel it switches back to my view (as it's supposed to do), but the keyboard won't show up. I already tried

好吧,这就是我的键盘行为:有一个按钮调用一个方法发送一个textmessage,工作正常。如果用户现在发送文本一切都很好。现在,如果他点击取消它切换回我的视图(因为它应该这样做),但键盘将不会显示。我已经试过了

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
   [self dismissModalViewControllerAnimated:YES];
   [inputView becomeFirstResponder];
}

since it didn't work I tried:

因为它不起作用我试过:

-(void)viewDidAppear:(BOOL)animated{
   [inputView becomeFirstResponder];
}

but that won't work either. So how can I get my keyboard to show up?

但这也行不通。那么如何让我的键盘显示出来呢?

EDIT: inputText is an UITextView.

编辑:inputText是一个UITextView。

1 个解决方案

#1


1  

This might be related to sending YES in dismissModalViewControllerAnimated:. When animations are involved, statements generally don't remain synchronous. So, your call to [inputView becomeFirstResponder] must be executing before the modal dialog has been dismissed, resulting in an inconsistent state. This is the reason why the inputView does not take focus.

这可能与在dismissModalViewControllerAnimated中发送YES有关:当涉及动画时,语句通常不会保持同步。因此,在取消模式对话框之前,必须执行对[inputView becomeFirstResponder]的调用,从而导致状态不一致。这就是inputView没有关注焦点的原因。

HTH,

Akshay

#1


1  

This might be related to sending YES in dismissModalViewControllerAnimated:. When animations are involved, statements generally don't remain synchronous. So, your call to [inputView becomeFirstResponder] must be executing before the modal dialog has been dismissed, resulting in an inconsistent state. This is the reason why the inputView does not take focus.

这可能与在dismissModalViewControllerAnimated中发送YES有关:当涉及动画时,语句通常不会保持同步。因此,在取消模式对话框之前,必须执行对[inputView becomeFirstResponder]的调用,从而导致状态不一致。这就是inputView没有关注焦点的原因。

HTH,

Akshay