我在我的视图中有一个搜索栏,是由用户用来输入一个关键字,并根据这一点进行搜索。为此,我使用了uisearchbar委托。现在地图正在进入关键字搜索的中心,但我也想显示与此相关的调用。我有lat和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;
}
}我怎么才能触发callout冒泡任何想法呢?
发布于 2012-05-23 06:53:05
我相信你已经解决了这个问题,但以防万一...根据苹果公司的文件,只有当大头针已经出现在屏幕上时,SelectAnnotation才能工作。
MKMapView类引用> SelectAnnotation如果指定的批注不在屏幕上,因此没有关联的批注视图,则此方法无效。
https://stackoverflow.com/questions/10433957
复制相似问题