有没有办法要求iOS查看哪个孩子有第一响应者身份? [英] Is there any way of asking an iOS view which of its children has first responder status?

查看:112
本文介绍了有没有办法要求iOS查看哪个孩子有第一响应者身份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X中,你可以找到这样的第一个响应者:

In Mac OS X, you can find the first responder like this:

[[self window] firstResponder]

在iOS中有什么办法吗?或者您是否需要枚举子控件并向每个控件发送 isFirstResponder 消息?

Is there any way of doing it in iOS? Or do you need to enumerate the child controls and send an isFirstRespondermessage to each one?

推荐答案

您需要遍历所有子控件并测试 isFirstResponder 属性。当您遇到 TRUE 时,请退出循环。

You would need to iterate over all of the child controls and test the isFirstResponder property. When you encounter TRUE, break out of the loop.

UIView *firstResponder;
for (UIView *view in self.view.subviews) //: caused error
{
    if (view.isFirstResponder)
    {
        firstResponder = view;
        break;
    }
}






更好的解决方案

请参阅雅各布的回答

这篇关于有没有办法要求iOS查看哪个孩子有第一响应者身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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