Asks UIKit to make this object the first responder in its window.
SDKs
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- UIKit
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 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 can
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.