Uiviewcontroller 键盘只出现一次

Uiviewcontroller 键盘只出现一次,uiviewcontroller,keyboard,notifications,Uiviewcontroller,Keyboard,Notifications,我以编程方式将UISearchBar添加到UIViewController中,方法是将其添加到我编写的视图中[self.searchBar becomeFirstResponder]和searchBar取消按钮点击和hideKeyboard两种方法中,我都有[self.searchBar resignFirstResponder] 我的代码还处理这两个通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selec

我以编程方式将UISearchBar添加到UIViewController中,方法是将其添加到我编写的视图中
[self.searchBar becomeFirstResponder]
searchBar取消按钮点击
hideKeyboard
两种方法中,我都有
[self.searchBar resignFirstResponder]

我的代码还处理这两个通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
我本来希望每次搜索栏获得焦点时(用户点击它)都能看到键盘,但结果是:键盘仅在我第一次执行搜索时出现,之后该框在字段中闪烁(它获得焦点,但键盘不会重新出现)


有什么建议吗?

不清楚您在找什么我希望键盘有正常的行为,当用户进入搜索文本字段时,键盘应该出现,当他消失时,在我的例子中,键盘只出现一次,并没有更多的代码。这还不足以解决这个问题problem@LithuT.V我已经编辑了这个问题:是否更好?是否在代码中添加了
resignFirstResponder
注释并重试