Protocol: UITextViewDelegate
Overview
The UITextViewDelegate protocol defines a set of optional methods you can use to receive editing-related messages for UITextView objects. All of the methods in this protocol are optional. You can use them in situations where you might want to adjust the text being edited (such as in the case of a spell checker program) or modify the intended insertion point.Asks the delegate whether the specified text should be replaced in the text view.Tells the delegate that editing of the specified text view has begun.Tells the delegate that the text or attributes in the specified text view were changed by the user.Tells the delegate that the text selection changed in the specified text view.Tells the delegate that editing of the specified text view has ended.Asks the delegate if editing should begin in the specified text view.Asks the delegate if editing should stop in the specified text view.
Instance Method Summary (collapse)
-
- textView:shouldChangeTextInRange:replacementText:
Asks the delegate whether the specified text should be replaced in the text view.
-
- textViewDidBeginEditing:
Tells the delegate that editing of the specified text view has begun.
-
- textViewDidChange:
Tells the delegate that the text or attributes in the specified text view were changed by the user.
-
- textViewDidChangeSelection:
Tells the delegate that the text selection changed in the specified text view.
-
- textViewDidEndEditing:
Tells the delegate that editing of the specified text view has ended.
-
- textViewShouldBeginEditing:
Asks the delegate if editing should begin in the specified text view.
-
- textViewShouldEndEditing:
Asks the delegate if editing should stop in the specified text view.
Instance Method Details
- (Boolean) textView(textView, shouldChangeTextInRange:range, replacementText:text)
Asks the delegate whether the specified text should be replaced in the text view. The text view calls this method whenever the user types a new character or deletes an existing character. Implementation of this method is optional. You can use this method to replace text before it is committed to the text view storage. For example, a spell checker might use this method to replace a misspelled word with the correct spelling.
- (Object) textViewDidBeginEditing(textView)
Tells the delegate that editing of the specified text view has begun. Implementation of this method is optional. A text view sends this message to its delegate immediately after the user initiates editing in a text view and before any changes are actually made. You can use this method to set up any editing-related data structures and generally prepare your delegate to receive future editing messages.
- (Object) textViewDidChange(textView)
Tells the delegate that the text or attributes in the specified text view were changed by the user. The text view calls this method in response to user-initiated changes to the text. This method is not called in response to programmatically initiated changes. Implementation of this method is optional.
- (Object) textViewDidChangeSelection(textView)
Tells the delegate that the text selection changed in the specified text view. Implementation of this method is optional. You can use the selectedRange property of the text view to get the new selection.
- (Object) textViewDidEndEditing(textView)
Tells the delegate that editing of the specified text view has ended. Implementation of this method is optional. A text view sends this message to its delegate after it closes out any pending edits and resigns its first responder status. You can use this method to tear down any data structures or change any state information that you set when editing began.
- (Boolean) textViewShouldBeginEditing(textView)
Asks the delegate if editing should begin in the specified text view. When the user performs an action that would normally initiate an editing session, the text view calls this method first to see if editing should actually proceed. In most circumstances, you would simply return YES from this method to allow editing to proceed. Implementation of this method by the delegate is optional. If it is not present, editing proceeds as if this method had returned YES.
- (Boolean) textViewShouldEndEditing(textView)
Asks the delegate if editing should stop in the specified text view. This method is called when the text view is asked to resign the first responder status. This might occur when the user tries to change the editing focus to another control. Before the focus actually changes, however, the text view calls this method to give your delegate a chance to decide whether it should. Normally, you would return YES from this method to allow the text view to resign the first responder status. You might return NO, however, in cases where your delegate wants to validate the contents of the text view. By returning NO, you could prevent the user from switching to another control until the text view contained a valid value.Be aware that this method provides only a recommendation about whether editing should end. Even if you return NO from this method, it is possible that editing might still end. For example, this might happen when the text view is forced to resign the first responder status by being removed from its parent view or window. Implementation of this method by the delegate is optional. If it is not present, the first responder status is resigned as if this method had returned YES.