Get the current first responder without using a private API

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

    The solution from romeo https://stackoverflow.com/a/2799675/661022 is cool, but I noticed that the code needs one more loop. I was working with tableViewController. I edited the script and then I checked. Everything worked perfect.

    I recommed to try this:

    - (void)findFirstResponder
    {
        NSArray *subviews = [self.tableView subviews];
        for (id subv in subviews )
        {
            for (id cell in [subv subviews] ) {
                if ([cell isKindOfClass:[UITableViewCell class]])
                {
                    UITableViewCell *aCell = cell;
                    NSArray *cellContentViews = [[aCell contentView] subviews];
                    for (id textField in cellContentViews)
                    {
                        if ([textField isKindOfClass:[UITextField class]])
                        {
                            UITextField *theTextField = textField;
                            if ([theTextField isFirstResponder]) {
                                NSLog(@"current textField: %@", theTextField);
                                NSLog(@"current textFields's superview: %@", [theTextField superview]);
                            }
                        }
                    }
                }
            }
        }
    }
    

提交回复
热议问题