Instance Method

becomeFirstResponder()

Asks UIKit to make this object the first responder in its window.

Declaration

func becomeFirstResponder() -> Bool

Return Value

true if this object is now the first-responder or false if it is not.

Discussion

Call this method when you want to the current object to be the first responder. Calling this method is not a guarantee that the object will become the first responder. UIKit asks the current first responder to resign as first responder, which it might not. If it does, UIKit calls this object's canBecomeFirstResponder method, which returns false by default. If this object succeeds in becoming the first responder, subsequent events targeting the first responder are delivered to this object first and UIKit attempts to display the object's input view, if any.

Never call this method on a view that is not part of an active view hierarchy. You can determine whether the view is onscreen, by checking its window property. If that property contains a valid window, it is part of an active view hierarchy. If that property is nil, the view is not part of a valid view hierarchy.

You can override this method in your custom responders to update your object's state or perform some action such as highlighting the selection. If you override this method, you must call super at some point in your implementation.

See Also

Managing the Responder Chain

var next: UIResponder?

Returns the next responder in the responder chain, or nil if there is no next responder.

var isFirstResponder: Bool

Returns a Boolean value indicating whether this object is the first responder.

var canBecomeFirstResponder: Bool

Returns a Boolean value indicating whether this object can become the first responder.

var canResignFirstResponder: Bool

Returns a Boolean value indicating whether the receiver is willing to relinquish first-responder status.

func resignFirstResponder()

Notifies this object that it has been asked to relinquish its status as first responder in its window.