ios - View 中多个搜索栏的方法

标签 ios uisearchbar

在一个 View 中,我有 2 个搜索栏,它们都需要使用单独的 searchBarTextDidBeginEditing 方法。但是,每当我尝试创建一个单独的方法时,都会显示为重复。使用一种方法,双方都在调用它。

我很确定我把方法弄错了。

searchBarTextDidBeginEditing:nearSearch searchBarTextDidBeginEditing:whatSearch

nearSearch 和 whatSearch 是两个不同的搜索栏。

我尝试了 nearSearch: searchBarTextDidBeginEditing 但我也不确定这是否正确。

最佳答案

委托(delegate)方法返回对调用它的搜索栏对象的引用,原因正是您所描述的问题,基本上您应该有对搜索栏的引用,并进行比较以了解哪个搜索栏正在调用方法并采取相应的行动..

说你已经定义了

UISearchBar *searchBarOne
UISearchBar *searchBarTwo

例如在你的委托(delegate)方法中

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
    {
      if(searchBar==searchBarOne)
      {
          //handle search bar one 
      }
      else if(searchBar==searchBarTwo)
      {
      //handle search bar two
      }
    }

另一种解决方案是为您的搜索栏设置不同的标签并比较这些标签,如您对问题的评论所述。

希望对你有帮助

丹尼尔

关于ios - View 中多个搜索栏的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22260074/

相关文章:

iphone - UI搜索栏表格 View

ios - 从带有搜索栏的 TableView Controller 移动到 UISearchDisplayController

iphone - iOS7 中 UISearchBar 委托(delegate)方法仅调用一次

ios - 搜索时 UITableview 不会重新加载

ios - 永远在后台运行 Swift 2.0 应用程序以将位置更新到服务器

ios - 在特定时间和日期调用 iOS 应用程序

ios - 通过 Braintree PayPal 支付总是失败 iOS

ios - 从 Storyboard 中使用 xib 调用 View Controller ?

ios - UISearchBar 返回类型

ios - 403 错误 - 这是一个错误。错误 : disallowed_useragent