ios - UIButton is not working on didSelectAnnotationView -
hi have custom view in didselectannotationview when user tap on pin maker i'm displaying custom view uilabel , uibutton working fine uibutton not clickable please tell how resolve issue.
my code.
-(void)mapview:(mkmapview *)mapview didselectannotationview:(mkannotationview *)view1 { nsstring *bult; if ([view1.annotation iskindofclass:[mappin class]]) { mappin *annot = view1.annotation; nslog(@"tit%@",annot.nsname); bult=annot.nsname; } myview = [[uiview alloc]initwithframe:cgrectmake(-60, -110, 200, 100)]; myview.layer.cornerradius = 10; myview.backgroundcolor = [uicolor yellowcolor]; myview.userinteractionenabled = yes; [view1 addsubview:test]; buldingname = [[uilabel alloc] initwithframe:cgrectmake(5, -15, 150, 80)]; buldingname.text=bult; [buldingname settextcolor:[uicolor blackcolor]]; [buldingname setbackgroundcolor:[uicolor clearcolor]]; [buldingname setfont:[uifont fontwithname: @"trebuchet ms" size: 14.0f]]; buldingname.linebreakmode = nslinebreakbywordwrapping; buldingname.numberoflines = 3; [myview addsubview:buldingname]; moredetail=[uibutton buttonwithtype:uibuttontyperoundedrect]; moredetail.frame= cgrectmake(0, 55, 200, 50); [moredetail settitle:@"click here more details" forstate:uicontrolstatenormal]; [moredetail addtarget:self action:@selector(nextbtn:) forcontrolevents:uicontroleventtouchupinside]; [moredetail setexclusivetouch:yes]; [myview addsubview:moredetail]; }
my calling method.
- (ibaction)nextbtn:(id)sender { nslog(@"click"); }
i have used above code not working please tell me i'm doing wrong how resolve issue.
thanks in advance.
it not working because mapview still handles touch event. add detailview in the:
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation { if ([annotation iskindofclass:[mkuserlocation class]]) { return nil; } static nsstring *reuseidentifier = @"your_identifier"; mkannotationview *view = [mapview dequeuereusableannotationviewwithidentifier:reuseidentifier]; if (view == nil) { view = [[mkannotationview alloc] initwithannotation:annotation reuseidentifier:reuseidentifier]; view.image = [uiimage imagenamed:@"your_annotaion_image.png"]; } view.canshowcallout = yes; uibutton* rightbutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; [rightbutton addtarget:self action:@selector(showdetails:) forcontrolevents:uicontroleventtouchupinside]; view.rightcalloutaccessoryview = rightbutton; uiimageview *icon = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"your_icon_image"]]; view.leftcalloutaccessoryview = icon; return view; }
and can call:
-(void)showdetails:(uibutton*)button { //do stuff here }
there absolutely no need build annotation callout view yourself, change design of default one.
Comments
Post a Comment