开发者

iPhone MKAnnotation with an ID for database content

Im trying to use the MKMap API and integrate a database table id so I can click a button detail disclosure to send the user to another page with further information. Ive been all over teh MKMapKit on the Apple site to find some property or method to help me with this and went over a few tutorials w开发者_JAVA百科ith no answers.

Ive tried to attach the id into the subtitle context so I can retrieve it in the MKAnnotationView where I make my MKPinAnnotationView and add teh button to the rightCalloutAccessoryView. It errors out and doesnt want to work.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{  

MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"mkpin"];  
annView.animatesDrop = YES;  
annView.canShowCallout = YES;  

UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
annView.rightCalloutAccessoryView = disclosureButton;  

return annView;  

}

I used this technique for an individual pin on a map and it seemed to work but I didnt require an id...

When I try to get the subtitle of the annotation it kills the app. I know the (id)annotation is an integer but I dont know how to manipulate this information. This function above I think is called after my code:

[mapView addAnnotations:markers]; //where markers is an array of title, subtitle aka id

Any help would be greatly appreciated.


The subtitle property is for a subtitle, not a database id. No good can come from abusing it in that way. Even if you could get it to work, it's a horrible approach.

All you have to do is give your annotation class an appropriate property to store your id. When you are passed the annotation, you can access it from there by casting to your annotation class. When you are passed the annotation view in other delegate methods, you can access the annotation through its annotation property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜