xcode 如何在 iPhone 中实现搜索栏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4774233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:07:48  来源:igfitidea点击:

How to implement search bar in iPhone?

iphoneobjective-cxcode

提问by Ajit

I am trying to implement a tab bar application in which a tab is provided with Search bar. When I click on the Search button after entering some data into the search field, I should get a tableviewdisplaying the search results. The tableviewshould be added as a subview. How should I implement this?

我正在尝试实现一个标签栏应用程序,其中提供了一个带有搜索栏的标签。当我在搜索字段中输入一些数据后单击“搜索”按钮时,我应该会tableview显示搜索结果。该tableview应添加作为一个子视图。我应该如何实施?

采纳答案by Waqas Raja

UISearchBar is a control in toolbox, you need to implement it, and implement search button press event to add tableview as a subview.

UISearchBar 是工具箱中的一个控件,需要实现它,并实现搜索按钮按下事件添加tableview作为子视图。

you can consult with the similar thread here

您可以在此处咨询类似的主题

UISearchBar Sample Code

UISearchBar 示例代码

回答by John Parker

You need to take a look at Apple's UISearchDisplayControllerclass reference documentation - this covers precisely what you're attempting to do and contains a link to a sample project (see the "Related sample code" section at the top) if you require some example code to look at.

如果您需要一些示例代码,您需要查看 Apple 的UISearchDisplayController类参考文档 - 这恰好涵盖了您尝试执行的操作并包含指向示例项目的链接(请参阅顶部的“相关示例代码”部分)看。

回答by Baddu

You will have to create two different tables

您将不得不创建两个不同的表

  1. One for showing all values.
  2. Second For showing searched result.
  1. 一个用于显示所有值。
  2. 第二个用于显示搜索结果。

and implement these two delegates of UISearchBarDelegate,UISearchDisplayDelegate

并执行这两个代表 UISearchBarDelegate,UISearchDisplayDelegate

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption