ios - IBAction in added xib subview does not work -
i have mapkit app. have replaced callout view view .xib file. when user taps on annotation subview appears following code:
func mapview(mapview: mkmapview!, didselectannotationview annotation: mkannotationview!) { if let pin = annotation.annotation as? custompointannotation{ if var infoview = uiview.viewfromnibname("myannview") as? myannview { infoview.namelabel.text = pin.thetitle infoview.detailslabel.text = pin.thedetails annotation.addsubview(infoview) } else { println("not right type") } } }
the .xib file has 2 labels , button. want when user presses button should "activate" segue, if click on button nothing. here code view:
class markerinfoview: mkannotationview { @iboutlet weak var placephoto: uiimageview! @iboutlet weak var namelabel: uilabel! @iboutlet weak var detailslabel: uilabel! @iboutlet weak var thebutton: uibutton! private var hitoutside:bool = true override func setselected(selected: bool, animated: bool) { let calloutviewadded = self.superview != nil println("mappin") if (selected || !selected && hitoutside) { super.setselected(selected, animated: animated) } self.superview?.bringsubviewtofront(self) // if (self == nil) { // self = myanninfoview() // } if (self.selected && !calloutviewadded) { addsubview(self) } if (!self.selected) { self.removefromsuperview() } } override func hittest(var point: cgpoint, withevent event: uievent?) -> uiview? { let viewpoint = superview?.convertpoint(point, toview: self) ?? point let isinsideview = pointinside(viewpoint, withevent: event) var view = super.hittest(viewpoint, withevent: event) println("evrika") return view } override func pointinside(point: cgpoint, withevent event: uievent?) -> bool { return cgrectcontainspoint(bounds, point) } @ibaction func readit(sender: anyobject) { println("evrika") } }
the "evrika" never appears. why action not called , how can make called?
why have hard time doing because not using default pins. instead using this: https://github.com/rvlvr/revclustermap
and have modified revclusterpin this:
#import "revclusterpin.h" @implementation revclusterpin @synthesize title,coordinate,subtitle; @synthesize nodes; @synthesize selected; - (nsuinteger) nodecount { if( nodes ) return [nodes count]; return 0; } - (uiview*)hittest:(cgpoint)point withevent:(uievent*)event { printf("hittest"); uiview* hitview = [super hittest:point withevent:event]; if (hitview != nil) { [super bringsubviewtofront:self]; } return hitview; } #if !__has_feature(objc_arc) - (void)dealloc { [title release]; [subtitle release]; [nodes release]; [super dealloc]; } #endif @end
thank much!
Comments
Post a Comment