2012-05-03 15 views
0

ユーザーがキーワードを入力して検索するために使用する検索バーがあります。私はこれのためにuisearchbarデリゲートを使用しています。現在、地図はキーワードが検索されている中心に来ていますが、それに関連するコールアウトを表示したいと思います。私は長いとタイトルがありますが、これは役に立つと思います。iosで検索した後にトリガーを呼び出す5

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ 
    NSLog(@"text %@",searchBar.text); 
    NSEnumerator *enumerator = [res objectEnumerator]; 
    id obj; 
    NSString *stringToSearchFor = [searchBar text]; 
    stringToSearchFor= [stringToSearchFor lowercaseString]; 
    NSString *searchInThisString = @""; 
    while(obj = [enumerator nextObject]){ 
     searchInThisString = [obj title]; 
     searchInThisString = [searchInThisString stringByAppendingString:@" "]; 
     searchInThisString = [searchInThisString stringByAppendingString:[obj address]]; 
     searchInThisString = [searchInThisString lowercaseString]; 
     if([searchInThisString rangeOfString:stringToSearchFor].location == NSNotFound){ 
      NSLog(@"not found "); 
      continue; 
     }else{ 
      NSLog(@"found"); 

      NSString *lat = [obj latitude]; 
      NSString *longi = [obj longitude]; 
      MKCoordinateRegion region = self.gpMapView.region; 
      region.center.latitude = [lat doubleValue]; 
      region.center.longitude = [longi doubleValue]; 
      id<MKAnnotation> myAnnotation = [self.gpMapView.annotations objectAtIndex:0]; 
      MKAnnotationView *mkv = [[MKAnnotationView alloc]init]; 
      [mkv setSelected:YES]; 
      [self.gpMapView selectAnnotation:myAnnotation animated:YES]; 
      [self.gpMapView setRegion:region animated:YES]; 

      break; 
     } 
    } 

がどのように任意のアイデアコールアウトバブルをしてくださいトリガすることができます:ここでは は、コードのですか?

答えて

1

Appleのドキュメントによれば、SelectAnnotationはピンが画面上にまだ表示されている場合にのみ機能します。

MKMapViewクラスリファレンス> SelectAnnotation 指定注釈が画面に表示されず、したがって、関連する注釈ビューを持っていない場合、このメソッドは効果がありません。

関連する問題