ios中多搜索栏的实现

ios中多搜索栏的实现,ios,objective-c,Ios,Objective C,我的视图控制器中有两个搜索栏。。。 正如所料,如果我触摸第一个搜索栏,它将进入第一个阶段。。 如果我点击第二个搜索栏,它将进入第二个搜索栏。。 这段代码很好用,但是如果我在其他屏幕较大或较小的iphone设备上运行这段代码。。 这将不起作用,因为我只使用了搜索栏的框架作为标识符 我已经搜索了很多,如果有其他方法来确定哪个搜索栏被点击,但我没有找到任何类似的实现。。 当我使用searchbar shouldbeginediting函数时,是否还有识别searchbar的方法 谢谢 - (B

我的视图控制器中有两个搜索栏。。。 正如所料,如果我触摸第一个搜索栏,它将进入第一个阶段。。 如果我点击第二个搜索栏,它将进入第二个搜索栏。。 这段代码很好用,但是如果我在其他屏幕较大或较小的iphone设备上运行这段代码。。 这将不起作用,因为我只使用了搜索栏的框架作为标识符

我已经搜索了很多,如果有其他方法来确定哪个搜索栏被点击,但我没有找到任何类似的实现。。 当我使用searchbar shouldbeginediting函数时,是否还有识别searchbar的方法

谢谢

    - (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!
检查在委托方法中单击的是哪一个。使用下面的代码段

- (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;