UIViewController - 不能成为第一响应者 [英] UIViewController - can't become first responder

查看:19
本文介绍了UIViewController - 不能成为第一响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这段代码时,任何人都知道为什么 UIViewController 不会成为第一响应者:

anyone knows why UIViewController wouldn't become first responder when I run this code:

[self becomeFirstResponder];
NSLog(@"is first resp: %i",[self isFirstResponder]);

在控制台中,我总是看到一行:"is first resp: 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 - 不能成为第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆