问题描述
当我运行此代码时,任何人都知道为什么UIViewController不会成为第一响应者:
anyone knows why UIViewController wouldn't become first responder when I run this code:
[self becomeFirstResponder];
NSLog(@"is first resp: %i",[self isFirstResponder]);
在控制台中,我总是看到这句话:是第一次:0
In the console, I always see the line: "is first resp: 0"
我有canBecomeFirstResponder方法:
I HAVE canBecomeFirstResponder method:
- (BOOL)canBecomeFirstResponder {
return YES;
}
我甚至不知道下一步要去哪儿....
I don't even know where to look next....
推荐答案
更新
我怀疑,我认为错误 UIViewController
/ firstResponder
用法。苹果开发论坛中的这个专门讨论了如何开始工作。
Update
As I suspected, I assumed wrong about UIViewController
/firstResponder
usage. This thread in the apple dev forums talks specifically about getting shaking to work.
在你的UI元素上调用 becomeFirstResponder
想回应。只要链中没有其他对象实现touches方法(或者至少继续将它们转发到链中),事件将自动转发到 UIViewController
。
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).
附注:为了建立其他人的评论, UIViewController
成为真的没有意义急救人员。第一个响应者应该是具有屏幕表示的对象( UIView
或其子类之一)。
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).
虽然这可能是一个完全不正确的陈述,但在 UIViewController
中可能存在无证行为,导致其无法成为firstResponder因为这些问题(比我聪明的人可以验证这个问题的有效性)。
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).
这篇关于UIViewController - 无法成为第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!