gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:51:53 26 4
gpt4 key购买 nike

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

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

searchBarTextDidBeginEditing:nearSearchsearchBarTextDidBeginEditing: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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com