anyone knows why UIViewController wouldn't become first responder when I run this code:
[self becomeFirstResponder];
NSLog(@"is first resp: %i",[self isFirstResponder]);
In the console, I always see the line: "is first resp: 0"
I HAVE canBecomeFirstResponder method:
- (BOOL)canBecomeFirstResponder {
return YES;
}
I don't even know where to look next....
Make sure you set your UIViewController to be first responder after you have assigned some view to your window instance.
As I suspected, I assumed wrong about UIViewController
/firstResponder
usage. This thread in the apple dev forums talks specifically about getting shaking to work.
Call becomeFirstResponder
on the UI element that you want to respond. The events will automatically get forwarded to the UIViewController
as long as no other objects in the chain implement the touches methods (or at least keep forwarding them up the chain).
Side note: To build on the comments of others, it really doesn't make sense for a UIViewController
to be the "first" responder. The first responder should be an object with an on screen representation (a UIView
or one of its subclasses).
Although this may be a completely incorrect statement, there may be undocumented behavior in UIViewController
that prevents it from becoming the firstResponder because of these issues (Someone smarter than me may be able to verify the validity of this).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With