Get the current first responder without using a private API

前端 未结 28 2555
夕颜
夕颜 2020-11-22 05:03

I submitted my app a little over a week ago and got the dreaded rejection email today. It tells me that my app cannot be accepted because I\'m using a non-public API; specif

28条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 05:55

    I would like to shared with you my implementation for find first responder in anywhere of UIView. I hope it helps and sorry for my english. Thanks

    + (UIView *) findFirstResponder:(UIView *) _view {
    
        UIView *retorno;
    
        for (id subView in _view.subviews) {
    
            if ([subView isFirstResponder])
            return subView;
    
            if ([subView isKindOfClass:[UIView class]]) {
                UIView *v = subView;
    
                if ([v.subviews count] > 0) {
                    retorno = [self findFirstResponder:v];
                    if ([retorno isFirstResponder]) {
                        return retorno;
                    }
                }
            }
        }
    
        return retorno;
    }
    

提交回复
热议问题