gpt4 book ai didi

ios - ios中的多个搜索栏实现

转载 作者:行者123 更新时间:2023-11-29 00:08:53 25 4
gpt4 key购买 nike

我的 View Controller 中有两个搜索栏...正如预期的那样,如果我触摸第一个搜索栏,它将转到第一个 segue..如果我触摸第二个搜索栏,它将转到第二个 segue..这段代码工作正常,但是如果我在其他屏幕更大或更小的 iphone 设备上运行它。这不会起作用,因为我只使用搜索栏的框架作为标识符..

如果有其他方法可以识别点击了哪个搜索栏,我已经搜索了很多,但我还没有找到这样的实现。当我使用函数 searchBarShouldBeginEditing..

时,是否仍然可以识别搜索栏

谢谢!

    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog(@"searchBarShouldBeginEditing");
NSLog(@" Description is: %@", NSStringFromCGRect(searchBar.frame));


if (([NSStringFromCGRect(searchBar.frame) isEqualToString:@"{{108, 27}, {267, 56}}"]) || ([NSStringFromCGRect(searchBar.frame) isEqualToString:@"{{108, 33}, {559, 56}}"]))
{
NSLog(@"to");
[self performSegueWithIdentifier:@"toSearchSegue" sender:self];
}
else if(([NSStringFromCGRect(searchBar.frame) isEqualToString:@"{{108, -3.5}, {267, 56}}"]) || ([NSStringFromCGRect(searchBar.frame) isEqualToString:@"{{108, -3.5}, {559, 56}}"]))
{
NSLog(@"from");
[self performSegueWithIdentifier:@"fromSearchSegue" sender:self];
}
else
{
[self performSegueWithIdentifier:@"searchSuggest" sender:self];
}
return YES;
}

最佳答案

您可以为每个 UISearchBars 设置两个导出,如下所示。

 @IBOutlet weak var firstSearchBar:UISearchbar!
@IBOutlet weak var secondSearchBar:UISearchbar!

检查委托(delegate)方法中单击了哪一个。使用下面的代码片段

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{


if (searchBar == firstSearchBar){
// perform actions for first bar
NSLog(@"to");
[self performSegueWithIdentifier:@"toSearchSegue" sender:self];
}

if (searchBar == secondSearchBar){
// perform actions for second search bar
NSLog(@"from");
[self performSegueWithIdentifier:@"fromSearchSegue" sender:self];
}



return YES;

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

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