objective c - Custom callout view with button over a MKMapview in iOS 3.0 -
i created subclass of mkannotationview
when selected display callout view (similar mkpinannotationview) subclass of uiview
button , text now. callout added annotation view. problem have button put in callout view never trigger action, not seem respond touch event.
the reason create new mkannotationview
because need display more text , 2 buttons in annotation view , not find way achieve regular mkpinannotationview
callouts.
code:
- (mkannotationview *) mapview:(mkmapview *) mapview viewforannotation:(id ) annotation { if(![annotation iskindofclass:[csmapannotation class]]) return nil; csmapannotation* csannotation = (csmapannotation*)annotation; customannotation *customannotationview=[[[customannotation alloc] initwithannotation:annotation reuseidentifier:nil] autorelease]; mkpinannotationview* pin = nil; pin = [[[mkpinannotationview alloc] initwithannotation:customannotationview reuseidentifier:@"identifier"] autorelease]; [pin setpincolor: mkpinannotationcolorred ]; mkannotationview *annotationview = pin; annotationview.canshowcallout = yes; [pin setpincolor:(csannotation.annotationtype == csmapannotationtypestart) ? mkpinannotationcolorgreen : ((csannotation.annotationtype == csmapannotationtypecarlocation)? mkpinannotationcolorpurple:mkpinannotationcolorred) ]; uiview *leftview = [[uiview alloc] initwithframe:cgrectmake(0,0,85,25)]; [leftview setbackgroundcolor:[uicolor clearcolor]]; uibutton *sharebutton = [uibutton buttonwithtype:uibuttontypecustom]; [sharebutton setbackgroundimage:[uiimage imagenamed:@"share.png"] forstate:uicontrolstatenormal]; [sharebutton setframe:cgrectmake(19+gap, 0, 25, 25)]; [sharebutton addtarget:self action:@selector(sharebuttonaction:) forcontrolevents:uicontroleventtouchupinside]; [leftview addsubview:sharebutton]; uibutton *setalertbutton = [uibutton buttonwithtype:uibuttontypecustom]; [setalertbutton setbackgroundimage:[uiimage imagenamed:@"alert.png"] forstate:uicontrolstatenormal]; [setalertbutton setframe:cgrectmake(sharebutton.frame.origin.x+sharebutton.frame.size.width+gap, 0, 25, 25)]; [setalertbutton addtarget:self action:@selector(alertbuttonaction:) forcontrolevents:uicontroleventtouchupinside]; [leftview addsubview:setalertbutton]; annotationview.rightcalloutaccessoryview = leftview; [leftview release]; return annotationview; } -(void)sharebuttonaction:(id)sender { nslog(@"%s",_cmd); }
the sharebuttonaction action not calling when clicking sharebutton...
i checked above delegate not called when installed iphone 3.0.. delegate call if have 1 button right callout (in above case)it not calling when adding view 2 buttons. happening in iphone 3.0.
i don't know if aware (or if care) passing mkannotationview method asks mkannotation , bound cause problems later down track.
also because of that, don't know if answer work there delegate method gels called when tap callout's accessory control. after setting mapview instance delegate, implement:
- (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control { nslog (@"callout accessory control tapped"); }
Comments
Post a Comment