ios - Delegate of TextField -


i faced , cannot understand it.

enter image description here

in tutorial watched, instructor press (cntrl + click) delegate option , drag viewcontroller class. then, textfield options become photo. searched lot , found explanation ,but couldn't understand exactly.

explanation : able use uitextfielddelegate methods, viewcontroller class must adopt protocol. however, before using method, have choose delegate option.

i cannot understand option. benefit of ?

so in order use , understand try out these steps:

1 adopt uitextfielddelegate protocol class so

    class myviewcontroller: uiviewcontroller, uitextviewdelegate { 

2 implement callback methods uitextviewdelegate. example:

    //mark: uitextviewdelegate      func textfield(_ textfield: uitextfield, shouldchangecharactersin range: nsrange, replacementstring string: string) -> bool {         print(textfield.text ?? "")         return true     } 

enter image description here

these methods made managing , validating text textview. maybe should read protocols.

or if don't understand why setting delegate form storyboard directly it's because way not have property declared in class. done seamlessly , not have in class:

    @iboutlet weak var mytextfield: uitextfield!      //...     override func viewdidload() {         super.viewdidload()         mytextfield.delegate = self     }  

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -