我有一個地圖視圖,上面有幾個註釋和一個搜索欄。在iOS 6中一切正常,但iOS 7中存在問題。在iOS 7中,當我選擇一個針時,標題彈出,我可以點擊信息按鈕以轉到該位置的詳細視圖。問題是,當我在iOS 7上搜索時,作爲搜索結果的註釋在註釋周圍出現黑色區域,我無法點擊信息按鈕。iOS地圖註釋問題
下面是選擇引腳上搜索:
這裏,它是尋找一個後:
這裏是我的,當你搜索會發生什麼代碼:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
id<MKAnnotation> ann;
BOOL annotationFound = NO;
// NSRange titleRange = [annTitle rangeOfString:searchText options:NSCaseInsensitiveSearch];
// NSRange subtitleRange = [annSubtitle rangeOfString:searchText options:NSCaseInsensitiveSearch];
for (int i = 0; i < [marketLocations count]; i++)
{
for (ann in marketLocations)
{
NSString *annTitle = ann.title;
NSString *annSubtitle = ann.subtitle;
NSString *searchText = [searchBar text];
NSRange titleRange = [annTitle rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSRange subtitleRange = [annSubtitle rangeOfString:searchText options:NSCaseInsensitiveSearch];
CLLocationCoordinate2D annCoord;
annCoord.latitude = ann.coordinate.latitude;
annCoord.longitude = ann.coordinate.longitude;
// if ([ann.title isEqualToString:[searchBar text]])
if (titleRange.location != NSNotFound)
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(annCoord, 5000, 5000);
[worldView setRegion:region animated:YES];
[worldView selectAnnotation:ann animated:YES];
annotationFound = YES;
}
// else if ([ann.subtitle isEqualToString:[searchBar text]])
else if (subtitleRange.location != NSNotFound)
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(annCoord, 5000, 5000);
[worldView setRegion:region animated:YES];
[worldView selectAnnotation:ann animated:YES];
annotationFound = YES;
}
}
}
if (annotationFound == NO)
{
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"" message:@"No Matches Found" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av dismissWithClickedButtonIndex:0 animated:YES];
[av show];
}
[searchBar resignFirstResponder];
}
它看起來像這個問題時註解結果是最後一個只發生它找到一個匹配,因此是顯示的那個。如果我在那裏添加中斷,問題不會顯示出來。這個問題雖然是我的搜索結果,雖然技術上正確,但不是我想要的。例如,如果我搜索haney,那麼我會得到chaney的註釋,因爲它首先得到它。 – raginggoat
對,所以你必須先循環所有註釋來找到「最佳匹配」,然後在循環之後調用selectAnnotation。 – Anna
我不知道如何找到最佳匹配。 – raginggoat