ios - How to call selector from switch only when change to state ON in Swift? -
i need phone call function selector when alter switch, when set switch on state:
cell.switchmy.addtarget(self, action: "openview", forcontrolevents: uicontrolevents.valuechanged) func openview(){ var cell:customcell = self.tableview.dequeuereusablecellwithidentifier("cell5") customcell if(cell.switchmy.on == true){ println("on") self.performseguewithidentifier("segueunl", sender: self) } }
if utilize code, phone call function, 'm controlling if switch state on... how can correctly?
this (nearly) right way this. can't have method called when switch state on
. don't need retrieve cell openview
method. sender passed caller:
cell.switchmy.addtarget(self, action: "openview:", forcontrolevents: uicontrolevents.valuechanged) func openview(sender: uiswitch){ if(sender.on) { println("on") self.performseguewithidentifier("segueunl", sender: self) } }
be careful: selector used in addtarget
needs changed openview
openview:
ios xcode swift
No comments:
Post a Comment