Tôi đã có một MKMapView
chú thích và tôi thêm như thế này:MKAnnotation không hiển thị chú thích trên MKMapView
for (NSDictionary *tmp in response)
{
NSDictionary *places = [tmp objectForKey:@"place"];
NSDictionary *location = [places objectForKey:@"location"];
NSLog(@"long: %@ Lat:%@",[location objectForKey:@"longitude"], [location objectForKey:@"latitude"]);
float longitude = [[location objectForKey:@"longitude"] floatValue];
float latitude = [[location objectForKey:@"latitude"] floatValue];
CLLocationCoordinate2D locationco = {latitude,longitude};
NSString *titleString = [tmp objectForKey:@"name"];
Place *pin = [[Place alloc] init];
pin.coordinate = locationco;
pin.title = titleString;
pin.subtitle = @"A Location";
//NSArray *annots = [[NSArray alloc] initWithObjects:pin, nil];
//[map addAnnotations:annots];
[map addAnnotation:pin];
[[map viewForAnnotation:pin] setCanShowCallout:YES];
}
Các MKAnnotation
's hiển thị trên bản đồ tốt, và tôi có thể chọn chúng, tuy nhiên không bong bóng chú thích xuất hiện. Tôi biết rằng họ đang được chọn đúng hình này
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[view setCanShowCallout:YES];
NSLog(@"Title:%@",[view.annotation description]);
}
Nhưng đó chỉ cần in ra
Title:(null)
Tôi đang sử dụng ARC, và tôi đã có các thuộc tính thiết lập trong đối tượng Nơi tôi như vậy :
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic,readwrite, copy) NSString *title;
@property (nonatomic,readwrite, copy) NSString *subtitle;
Tôi đang làm gì sai/thiếu? Cảm ơn.
Trước dòng 'addAnnotation', bạn có thể NSLog' pin.title' và xem nội dung hiển thị không? Ngoài ra, trong đối tượng Place bạn đã ghi đè phương thức 'description' bằng bất kỳ cơ hội nào và nếu có mã nào trong đó? – Anna
'NSLog (@"% @ ", pin.title);' Chỉ trả về '(null)'. Tôi không hiểu tại sao. –