IOS Swift - Manually trigger textfield events -


how trigger events manually given uitextfield object?

textfieldshouldbeginediting(_:) textfielddidbeginediting(_:) textfieldshouldendediting(_:) textfielddidendediting(_:) 

in current scenario. there logic goes above callbacks. , there times when manually update textfield

textfield.text = <new text> 

and

textfielddidbeginediting 

to trigger, (hopefully)

textfield.trigger("textfielddidbeginediting") 

while approach might not entirely right way, above solution works me. although, if can word question differently, be:

  • how can run logic (code) when uitextfields value (text) changed via ui or via textfield.text = <new value>

to elaborate on answer , reasoning:

i don't think possible trigger kind of events "by hand" - neither should able to. cause possibly more problems solves. e.g. should happen caret example, should displayed in textfield?

therefore suggest extract logic second method , call method current code , handler

instead of

func textfielddidendediting(textfield: uitextfield) {     // logic here     let k = 1 + 2 }  func yourcurrentcode() {     // somehow trigger event "textfielddidendediting" } 

do like

func textfielddidendediting() {     mylogic() }  func yourcurrentcode() {     mylogic() }  func mylogic() {     // logic should here     let k = 1 + 2 } 

if notified every time value of uitextfield changes should use notification

uitextfieldtextdidchangenotification 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -