如何使用搜索栏实现基于单字母的搜索?
我需要在我的 iPhone 应用程序中拥有一个搜索栏控件,但我希望拥有它,以便您可以仅使用单个字母进行搜索。例如,我想在搜索框中输入一个字母,然后显示以该字母开头的项目列表。
我将如何实现这样的事情?
I need to have a search bar control in my iPhone application, but I'd like to have it so that you can search using only a single letter. For example, I'd like to enter a letter into the search box and have a list of items starting with that letter appear.
How would I implement something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 UISearchBarDelegate 上使用
searchBar:textDidChange:
方法。Try using the
searchBar:textDidChange:
method on UISearchBarDelegate.iOS 中的下拉列表主要是表格视图。您有两个选择 - 使用带有表视图的搜索栏并响应其委托方法。代表将在文本输入时向您发送消息。您将需要处理它并为表视图提供正确的数据。这是非常基本的东西。事情看起来有点复杂,你可以看看
UISearchDisplayController
。这是实现上述相同目标的便利工具。现在的问题是想办法及时处理。对于较小的数据集,您可能可以进行现场过滤,但对于较大的数据集,您需要某种索引。否则你可能会得到糟糕的用户体验。
Take a look at tutorials to feel comfortable.
The drop down list is mostly a table view in iOS. You have two options – Use a search bar with a table view and respond to its delegate method. The delegate will message you on text entry. You will need to process it and feed the table view with proper data. This is pretty basic stuff. It things seem a bit complex, you can look at
UISearchDisplayController
. This is a convenience tool to achieving the same thing mentioned above.Now, the issue is to figure out a way to process it within time. For a smaller data set, you could probably go for on the spot filtering but with larger data sets, you need to have some sort of indexing. Otherwise you might end up with bad user experience.
Take a look at tutorials to feel comfortable.