从单独的班级中辞去第一响应者
我有一个类,它制作一个键盘工具栏,上面有“下一步”、“上一个”和“完成”按钮。有没有办法让这个类随时知道(或找出)屏幕上有哪些对象?
例如,它能否看到当前视图是什么以及其上的文本字段是什么,然后能够放弃第一响应者?
I have a class that makes a keyboard toolbar which has "Next", "Previous", and "Done" buttons on it. Is there a way for this class to know (or find out) what objects are on the screen at any time?
E.g., can it see what the current view is and what the text fields on it are, and then be able to resign the first responder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您特别想辞职第一响应者,而不需要知道哪个视图是第一响应者,您可以将 resignFirstResponder 发送到“nil”,如下所示:
这是记录的行为,尽管我现在无法在文档中找到。
If you specifically want to resign first responder without the need to known which view is the first responder you can send resignFirstResponder to "nil" like this:
This is documented behaviour although I cannot find in the docs right now.
找到 momma 视图,您可以像这样迭代屏幕上的所有对象(因为它们也是 UIView)。请注意,您可能需要添加递归:
Find the momma view and you can iterate through all the objects on the screen (because they will be UIViews too) like this. Note that you may need to add recursion:
您可以从 Window 类开始,然后从那里向下,询问 [view respondsTo:@selector(isFirstResponder) &&每个上的 [view isFirstResponder]。我使用的一些调试代码可能会作为模板以及在调试时派上用场:
You can start at the Window class and go down from there, asking [view respondsTo:@selector(isFirstResponder) && [view isFirstResponder] on each. Some debugging code that I use might come in handy as a template and also while debugging:
是的,只要文本字段变为活动状态,就会调用下面提供的方法。我认为您正在寻找
或
,如果您正在视图中寻找特定的文本字段,您应该为它们分配标签:
yes, the methods provided below will be called whenever a textField becomes Active. I think you are looking for
or
and if you are looking for a specific textField in your view, you should assign them tags: