2

Here is a minimal working example illustrating the issue: https://bitbucket.org/7331/firstrespondertest/.


What object is set as the First Responder of the keyWindow after the Single View Application starts up (suppose that I haven't interacted with the application yet and my code doesn't explicitly call becomeFirstResponder())?

In other words – what object sets the First Responder to the initial value? (Or what is the First Responder of a newly created UIWindow?)

As I was debugging the Single View Application, I inspected* the First Responder of the keyWindow and found out that it was nil – which seems odd given that the ViewController's motionBegan() gets called when the device is shaken (despite the fact that canBecomeFirstResponder() returns false).

class ViewController: UIViewController {
    override func canBecomeFirstResponder() -> Bool {
        return false
    }

    override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent?) {
        print("motionBegan")
    }
}

Moreover: when I load a nib file via UINib, do the nib's subviews get called becomeFirstResponder() by UINib's initializer internally?


*I used the UIWindow's private API to inspect the First Responder. In LLDB: po UIApplication.sharedApplication().keyWindow!._firstResponder().

sarasvati
  • 792
  • 12
  • 30

0 Answers0