У меня большие проблемы с выяснением того, что я делаю не так здесь ... Я добавляю аннотации к моим схемам просмотра через циклы, но изображение аннотации абсолютно случайное каждый раз ... когда я NSLog
заказ, он случайный - я не уверен, что это проблема.mapview случайное изображение аннотации
- (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([[annotation subtitle] isEqual:@"Bar"]) {
MKAnnotationView *view = nil;
view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
if (!view) {
// Could not reuse a view ...
// Creating a new annotation view
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
view.enabled = YES;
view.canShowCallout = YES;
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
view.image = [UIImage imageNamed:@"beer.png"];
}
return view;
}
else if ([[annotation subtitle] isEqual:@"Club"]) {
MKAnnotationView *view = nil;
view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
if (!view) {
// Could not reuse a view ...
// Creating a new annotation view
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
view.enabled = YES;
view.canShowCallout = YES;
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
view.image = [UIImage imageNamed:@"clubs.png"];
}
return view;
}
}
view.image совершенно случайным образом ... либо clubs.png
или beer.png
.. Как сделать это правильно?
это, как я добавить аннотации:
- (void)barLoop {
for (int i = 0; i<barArray.count; i++) {
int index = [[barArray objectAtIndex:i]intValue];
NSString *lati = [[[self.usersLocationArray objectAtIndex:index]
valueForKeyPath:@"items.Latitude"]componentsJoinedByString:@""];
NSString *longi = [[[self.usersLocationArray objectAtIndex:index]
valueForKeyPath:@"items.Longitude"]componentsJoinedByString:@""];
NSString *barNavn = [[[self.usersLocationArray objectAtIndex:index] valueForKeyPath:@"items.Navn"]componentsJoinedByString:@""];
float latitude = [lati floatValue];
float longitude = [longi floatValue];
MKCoordinateRegion region = { {0.0, 0.0} , {0.0, 0.0} };
region.center.latitude = latitude;
region.center.longitude = longitude;
region.span.longitudeDelta = 0.20f;
region.span.latitudeDelta = 0.20f;
[mapView setRegion:region animated:NO];
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
Annotation *ann = [[Annotation alloc]initWithPosition:location];
ann.title = barNavn;
ann.subtitle = @"Bar";
[self.mapView addAnnotation:ann];
}
}
заранее спасибо :)
спасибо большое! использование другого reuseIdentifier решило мою проблему :) Я собираюсь попробовать свою удачу с предложением определить, что это клуб или бар - имеет смысл иметь адрес бара/клуба. Огромное спасибо! –