Reputation: 5588
In my iOS app, I would like to set the delegate of my PageViewController's main UIScrollView
.
There is tons of answer that say : "Ok man, juste iterate over subview and you will find the scrollview".
Ok, it works, but does it pass the Apple Validation Step ? Is it not a call to private API ? Does someone successfully published an app with this trick ?
Thanks everyone,
Upvotes: 0
Views: 346
Reputation: 27550
In short, no, this is not going to trip Apple's validation step. See this answer for a list of ways Apple detects private API usage. They're mostly looking for if you reference a private class or selector. For instance UIKeyboardImpl
or _setViewDelegate:
.
I personally have something very similar in the app store. I needed to get the UITextField
in a UISearchBar
so I have the following code:
UIView<UITextInput> *UISearchBarTextInput(UISearchBar *searchBar) {
for (id view in searchBar.subviews) {
// Could be in the top level. (iOS6)
if ([view conformsToProtocol:@protocol(UITextInput)]) {
return view;
}
// Or the next level. (iOS7)
for (id subview in [view subviews]) {
if ([subview conformsToProtocol:@protocol(UITextInput)]) {
return subview;
}
}
}
return nil;
}
The big problem you are likely to run into is that you are dealing with a private view hierarchy and Apple makes no guarantees that this will stay constant between iOS releases. In the code above I have to support two different iOS versions. If they decided to make a change in iOS9 I would have to make modify my code. It's a good practice in this case to assume that your lookup may fail (you won't be able to find the scroll view or a new scroll view may be added) and make your code resilient to that case.
Also, you have to consider that a human will use your app as part of the app store review. If you change things too much from the expected behavior it can be rejected on that alone.
Upvotes: 1