简体   繁体   English

一个ViewController中可以有两个UISearchBar吗?

[英]Can I have two UISearchBar in one ViewController?

Can I have two UISearchbar in one ViewController ? 我可以在一个ViewController有两个UISearchbar吗?

Basically I have a map view and I want to put a source and destination UISearchBar on top. 基本上,我有一个地图视图,我想将源和目标UISearchBar放在顶部。

Now if I add two UIISearchBar and thus two UISearchDisplayControllers , how do I determine which search bar it is in use in the delegate functions ? 现在,如果我添加两个UIISearchBar并因此添加两个UISearchDisplayControllers ,如何确定委托函数中正在使用哪个搜索栏?

I was planning to use just one UISearchBar which will take source first and then destination, but now the plan is to show 2 search bars. 我打算只使用一个UISearchBar ,它将首先获取源,然后获取目的地,但是现在计划显示2个搜索栏。

I got everything working with one search bar. 我可以使用一个搜索栏进行所有操作。

You will have to store both UISearchBars in an IBOutlet like 您将必须将两个UISearchBars存储在IBOutlet中,例如

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

Then in your delegates do 然后在您的代表中

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

This approach can also be used when you have to deal with more than one UIAlertView, UITableView, UICollectionView etc. 当您必须处理多个UIAlertView,UITableView,UICollectionView等时,也可以使用这种方法。

我想我想通了...我必须创建uisearchdisplaycontrollers的属性,然后我可以引用searchtableview等来找出正在使用的uisearchbar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以让 UISearchBar 成为它自己的 inputAccessoryView 吗? - Can I have a UISearchBar be its own .inputAccessoryView? 如何将两个委托放到一个视图控制器 - How can I put two delegate to one viewcontroller 我如何在 swift 3 的一个视图控制器中填充两个不同的表视图 - How i can fill two different tableview in one viewcontroller in swift 3 如何在一个 ViewController 中使用两个 Webview? - how can I use two Webviews in one ViewController? 如何在另一个ViewController之上显示一个ViewController? - How can I present one ViewController on top of another ViewController? 我可以使用一个viewController而不是5吗? - Can I use one viewController instead of 5? 您可以为不同的目标使用同名的ViewController的两个实现吗? - Can you have two implementations of a ViewController with the same name for differen targets? 使用UISearchBar加载其他ViewController - Load a different ViewController with UISearchBar 我可以在iOS7的其他ViewController中使用NSURLSession委托方法吗? - Can I have a NSURLSession delegate method in a different ViewController in iOS7? 我可以显示全屏 ViewController,但仍然可以向下滑动以返回父(启动器)ViewController - Can I have Full Screen ViewController presented, but still able to swipe down, to get back to Parent (launcher) ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM