gpt4 book ai didi

ios - 我可以在一个 ViewController 中有两个 UISearchBar 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:06 25 4
gpt4 key购买 nike

我可以在一个 ViewController 中有两个 UISearchbar 吗?

基本上我有一个 map View ,我想在顶部放置一个源和目标 UISearchBar

现在,如果我添加两个 UIISearchBar,从而添加两个 UISearchDisplayControllers,我如何确定它在委托(delegate)函数中使用的是哪个搜索栏?

我原计划只使用一个 UISearchBar,它会先获取源,然后再获取目标,但现在的计划是显示 2 个搜索栏。

我用一个搜索栏就搞定了一切。

最佳答案

您必须将两个 UISearchBar 存储在 IBOutlet 中,例如

@property (nonatomic, weak) IBOutlet UISearchBar *firstSearchBar;
@property (nonatomic, weak) IBOutlet UISearchBar *secondSearchBar;

然后在你的委托(delegate)中做

- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
if (searchBar == self.firstSearchBar) {
// Do something
} else {
// Do something else
}
}

当您必须处理多个 UIAlertView、UITableView、UICollectionView 等时,也可以使用这种方法。

关于ios - 我可以在一个 ViewController 中有两个 UISearchBar 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22087858/

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