How to have the iOS SearchBar Keyboard Search Button Perform an Action

对着背影说爱祢 提交于 2019-12-06 14:08:50

try this:

searchBar.delegate = delegateInstance;

//delegateInstance.m
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
   //perform the same functionality of the create button 
}
Jissay

You can catch the event fired by tapping the search button this way :

UISearchDisplayController has a UISearchBar, you can set a delegate for search bar and implement -searchBarSearchButtonClicked:.

From now, you should be able to call the same treatment that you do on create button. Found this answer on this post. Hope that helps !

I don't think you can find a right keyboard ReturnKeyType for "Create" or "Add" to let user know the return key of the keyboard will create a user. =)

Anyway, I guess what you want is if you click "search" button second time with no search result displayed on the tableview then you want to create a user with new search text on the search bar. Did I understand right? If so, I think I already answered your question.

In UISearchBarDelegate, – searchBarSearchButtonClicked:, Check if you don't have any search results and have any text in the search bar, then you can create a user.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!