Get the current first responder without using a private API

前端 未结 28 1847
夕颜
夕颜 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:51

    This is what I have in my UIViewController Category. Useful for many things, including getting first responder. Blocks are great!

    - (UIView*) enumerateAllSubviewsOf: (UIView*) aView UsingBlock: (BOOL (^)( UIView* aView )) aBlock {
    
     for ( UIView* aSubView in aView.subviews ) {
      if( aBlock( aSubView )) {
       return aSubView;
      } else if( ! [ aSubView isKindOfClass: [ UIControl class ]] ){
       UIView* result = [ self enumerateAllSubviewsOf: aSubView UsingBlock: aBlock ];
    
       if( result != nil ) {
        return result;
       }
      }
     }    
    
     return nil;
    }
    
    - (UIView*) enumerateAllSubviewsUsingBlock: (BOOL (^)( UIView* aView )) aBlock {
     return [ self enumerateAllSubviewsOf: self.view UsingBlock: aBlock ];
    }
    
    - (UIView*) findFirstResponder {
     return [ self enumerateAllSubviewsUsingBlock:^BOOL(UIView *aView) {
      if( [ aView isFirstResponder ] ) {
       return YES;
      }
    
      return NO;
     }];
    }
    

提交回复
热议问题