core data - How to get the managed object from selected annotation -
i have model: event, have loaded annotation view mapview, how event managed object selected annotation, can force view controller display event's info. viewforannotation part:
- (mkannotationview *)mapview:(mkmapview *)amapview viewforannotation:(id <mkannotation>)annotation { if([annotation class] == mkuserlocation.class) { //userlocation = annotation; homecoming nil; } revclusterpin *pin = (revclusterpin *)annotation; mkannotationview *annview; annview = [amapview dequeuereusableannotationviewwithidentifier:@"pin"]; if( !annview ) annview = [[mkannotationview alloc] initwithannotation:annotation reuseidentifier:@"pin"]; annview.image = [uiimage imagenamed:@"pinpoint.png"]; annview.canshowcallout = yes; uibutton *rightbutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; [rightbutton addtarget:self action:@selector(displayviewcontroller:) forcontrolevents:uicontroleventtouchupinside]; annview.rightcalloutaccessoryview = rightbutton; annview.calloutoffset = cgpointmake(-6.0, 0.0); } homecoming annview; }
and rightcalloutaccessoryview displayviewcontroller part :
- (void)displayviewcontroller:(id)sender { annotation *annotation = [self.mapview selectedannotations][0]; eventsviewcontroller *eventsvc = [[eventsviewcontroller alloc] init]; eventsvc.event = ??? [self.navigationcontroller pushviewcontroller:eventsvc animated:yes]; }
how managed object annotation *annotation = [self.mapview selectedannotations][0] ? if declare event in annotation, what?
the class annotation own not? contain property holding event
? if not should.
if remove custom selector you've assigned rightbutton , you've set delegates correctly should phone call function
- (void)mapview:(mkmapview *)map annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control { revclusterpin *annotation = (revclusterpin *)view.annotation; eventsviewcontroller *eventsvc = [[eventsviewcontroller alloc] init]; eventsvc.event = annotation.event; [self.navigationcontroller pushviewcontroller:eventsvc animated:yes]; }
core-data annotations mkmapview cllocationmanager
No comments:
Post a Comment