查找作为第一响应者的视图 [英] Find View that is the firstresponder

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

问题描述

我想获得第一个响应者的视图,目前我有一个包含UITextFields的UITableView,使用方法:

I would like to get the view that is the first responder, currently I have a UITableView that contains UITextFields, using a method:

-(UIView*) findFirstResponder
{

}

我希望能够获得第一个响应者视图,然后对该视图执行某些操作。

I would like to be able to get the view that is the firstResponder and then do something with that view.

任何想法?

推荐答案

我所要做的只是

@implementation UIView (FindViewThatIsFirstResponder)
- (UIView *)findViewThatIsFirstResponder
{
    if (self.isFirstResponder) {        
        return self;     
    }

    for (UIView *subView in self.subviews) {
        UIView *firstResponder = [subView findViewThatIsFirstResponder];
        if (firstResponder != nil) {
            return firstResponder;
        }
    }

    return nil;
}
@end

这篇关于查找作为第一响应者的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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