在以下方法中:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
我目前有以下 22 个:
if ([[annotation title] isEqualToString:@"Arcadian Winery"]) {
[profileIconView setImage:[UIImage imageNamed:@"arcadian.png"]];
}
if ([[annotation title] isEqualToString: @"Babcock Winery and vineyards"]) {
[profileIconView setImage:[UIImage imageNamed:@"babcock.png"]];
}
if ([[annotation title] isEqualToString:@"Bonny Doon Vineyard"]) {
[profileIconView setImage:[UIImage imageNamed:@"bonnyDoon.png"]];
}
我想用以下数组替换它,但它只返回最后一个对象。
NSArray *wineryTitle = [NSArray arrayWithObjects:
@"Arcadian Winery",
@"Babcock Winery and vineyards",
@"Bonny Doon Vineyard",
@"Castoro Cellars",
@"Dry Creek Vineyard",
@"Gary Farrell Wines, Inc.",
@"Equinox Methode Champenoise",
@"Figge Cellars",
@"Frog's Leap Winery",
@"Heitz Wine Cellars",
@"Kathryn Kennedy",
@"Merryvale Vineyards",
@"Manzoni Estate Vineyard",
@"Marilyn Remark Winery",
@"Bernardus Vineyards & Winery",
@"Nickel & Nickel",
@"Opolo Vineyards, Inc.",
@"Riverbench Vineyard and Winery",
@"Steven Kent Winery",
@"Storrs Winery",
@"Talley Vineyards",
@"Thomas Fogarty Winery",
nil];
NSArray *wineryImage = [NSArray arrayWithObjects:
@"arcadian.png",
@"babcock.png",
@"bonnyDoon.png",
@"castoro.png",
@"dryCreek.png",
@"garyFarrell",
@"EquinoxMethodeChampenoise.png",
@"figge.png",
@"frogsLeap.png",
@"heitz.png",
@"kathrynKennedy.png",
@"merryvale.png",
@"manzoni.png",
@"mailynRemark.png",
@"bernardus.png",
@"nickelAndNickel.png",
@"opolo.png",
@"riverbench.png",
@"stevenKent.png",
@"storrs.png",
@"talley.png",
@"thomasFogarty.png",
nil];
for (int i = 0; i < 22; i++) {
UIImageView *profileIconView = [[UIImageView alloc] init];
if ([[wineryTitle objectAtIndex:i] isEqualToString:[wineryTitle objectAtIndex:i]]) {
[profileIconView setImage:[UIImage imageNamed:[wineryImage objectAtIndex:i]]];
}
profileIconView.frame = CGRectMake(0, 0, 40, 33);
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
}
return pinView;
该数组正确地遍历标题字符串,但始终仅将最后一个图像返回到注释。