首页 > 代码库 > UITextfield代理方法传递

UITextfield代理方法传递

The sequence of messages that both text views and text fields send to their delegates is as follows:
      1. Just before a text object becomes first responder—textFieldShouldBeginEditing: (text field) and

textViewShouldBeginEditing: (text view).The delegate can verify whether the text object should become first responder by returning YES (thedefault) or NO.

  1. Just after a text object becomes first responder—textFieldDidBeginEditing: (text field) andtextViewDidBeginEditing: (text view).

    The delegate can respond to this message by updating state information or, for example, by showing anoverlay view during the editing session.

  2. During the editing session—various.

    While the user enters and edits text, the text object invokes certain delegation methods (if implemented).For example, the delegate of a text view can receive a textViewDidChange: message when any textchanges. The delegate of a text field can receive a textFieldShouldClear: message when the usertaps the clear button of a text field; the delegate returns a Boolean value indicating whether the textshould be cleared.

  3. Just before a text object resigns first responder—textFieldShouldEndEditing: (text field) andtextViewShouldEndEditing: (text view).

    The primary reason for a delegate to implement these methods is to validate entered text. For example,if text should conform to a given format, the delegate validates the entered string here and returns NO ifthe string does not conform. The default return value is YES.

    A related method for text fields is textFieldShouldReturn:. When the user taps the return key, thetext field class sends a textFieldShouldReturn: message to the delegate to ask whether it shouldresign first responder.

  4. Just after text a object resigns first responder—textFieldDidEndEditing: (text field) andtextViewDidEndEditing: (text view).