如何让iOS SearchBar键盘搜索按钮执行操作 [英] How to have the iOS SearchBar Keyboard Search Button Perform an Action

查看:1126
本文介绍了如何让iOS SearchBar键盘搜索按钮执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,它具有一个表视图(TV1),用户通过选择添加条目"(VC1)的导航栏按钮项来填充该表视图.在添加条目"中,当用户按下名称"字段时,会将他们带到另一个表视图(TV2),其目的是允许用户选择以前输入的名称或创建新名称.

I have a simple application which has a Table View (TV1) which gets populated by the user selecting a navigation bar button item to Add Entry (VC1). Within the Add Entry, when the user presses the Name field, they're taken to another Table View (TV2) which serves the purpose of allowing the user to select a previously entered name or create a new name.

TV2是一个表视图控制器,顶部带有搜索栏.

TV2 is a Table View Controller with a Search Bar at the top.

现在,现有名称可用并显示给用户.但是,如果用户搜索"不存在的名称,则他们应该可以选择立即创建该名称.如果不存在搜索,我有一个用户可以点击的按钮,它将创建用户.很简单但是,这是另一回事.

Right now, existing names are available and show to the user. However, if the user "searches" for a name that does not exist, they should have the option to Create that name right now. If a search does not exist, I have a button which the user can tap which will create the user. That's simple. However, it's another tap.

有没有一种方法可以让键盘的搜索"按钮执行与创建"按钮相同的功能(即保存新用户并关闭TV1),然后使我可以删除键盘中间的创建"按钮.表格视图?

Is there a way I can get the Search button of the Keyboard to perform the same functionality of the create button (i.e. Save the new user and dismiss TV1) which would then allow me to remove the Create button in the middle of the table view?

推荐答案

尝试一下:

searchBar.delegate = delegateInstance;

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

这篇关于如何让iOS SearchBar键盘搜索按钮执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆