我的视图中有一个搜索栏,用户可以使用它来输入关键字并根据该关键字进行搜索。我为此使用 uisearchbar 委托。现在地图正在搜索关键字的中心,但我也想显示与此相关的调用。我有 lat long 和 title,我认为这很有用。这是代码:
- (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;
}
}
请问我怎样才能触发标注气泡?