ios - How to add a default parameter value in the #selector -
this question has answer here:
- add static parameter #selector in swift 3 answers
i have function:
func handlechange(isshown:bool){ if isshown { // }else{ // b } } if want uislider add above action isshown defaulting false, , call method handlechange(isshown:bool) true in function. wrong code follows:
slider.addtarget(self, action: #selector(handlevalue(isshown:false)), for: .valuechanged) and know right code needs be:
slider.addtarget(self, action: #selector(handlevalue(isshown:)), for: .valuechanged) i want know how can set 'isshown' false in swift? appreciate can reply.
one solution use helper function separate selector function. selector function can call helper function, can have many parameters wish.
adding target:
slider.addtarget(self, action: #selector(handlechange(_ sender: uislider)), for: .valuechanged) target function:
func handlechange(sender: uislider) { // logic based on action or slider dosomething(isshown: true) } helper function:
func dosomething(isshown: bool) { // make changes using parameters here }
Comments
Post a Comment