ios - Delegate of TextField -
i faced , cannot understand it.
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 }
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
Post a Comment