ios - Swift unrecognized selector sent to instance segmented control -
i trying add selector uisegmentedcontrol.
segmentedcontrol = uisegmentedcontrol(items: items) segmentedcontrol.layer.cornerradius = 12.0 segmentedcontrol.layer.bordercolor = uicolor.purplelight.cgcolor segmentedcontrol.layer.borderwidth = 1.0 segmentedcontrol.layer.maskstobounds = true segmentedcontrol.backgroundcolor = .white self.contentview.addsubview(segmentedcontrol) segmentedcontrol.addtarget(self, action: selector(("changecolor:")), for:.valuechanged)
then:
func changecolor(sender: uisegmentedcontrol) { switch sender.selectedsegmentindex { case 1: segmentedcontrol.backgroundcolor = uicolor.green case 2: segmentedcontrol.backgroundcolor = uicolor.blue default: segmentedcontrol.backgroundcolor = uicolor.purple } }
however, when tap it, got error - unrecognized selector sent instance 0x7fcf5f049000
replace action argument - selector. since swift 3, selector syntax has been changed.
segmentedcontrol.addtarget(self, action: #selector(self.changecolor(sender:)), for:.valuechanged)
Comments
Post a Comment