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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -