I’d like to use a popover view for iPhone.
I found a 3rd party library and author says some of its method is utilizing a private method.(which will cause problem when submitting to app store)
But I don’t see where is private method being used in his code.
Can you spot them?
[barButtonItem performSelector:@selector(view)] is considered to be calling a private method?
https://github.com/sonsongithub/PopupView/blob/master/SNPopupView%2BUsingPrivateMethod.m
- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
if(![barButtonItem respondsToSelector:@selector(view)]) {
// error
return;
}
UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];
UIView *targetSuperview = [targetView superview];
BOOL isOnNavigationBar = YES;
if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
isOnNavigationBar = YES;
}
else if ([targetSuperview isKindOfClass:[UIToolbar class]]) {
isOnNavigationBar = NO;
}
else {
// error
return;
}
CGRect rect = [targetSuperview convertRect:targetView.frame toView:inView];
CGPoint p;
p.x = rect.origin.x + (int)rect.size.width/2;
if (isOnNavigationBar)
p.y = rect.origin.y + rect.size.height + BAR_BUTTON_ITEM_UPPER_MARGIN;
else
p.y = rect.origin.y - BAR_BUTTON_ITEM_BOTTOM_MARGIN;
[self showAtPoint:p inView:inView animated:animated];
}
You’re not supposed to access the
viewproperty of aUIBarButtonItem. That’s where the private call is:See the official doc for
UIBarButtonItem, it has no publicviewproperty.Though, it’s not really a private call as the
viewmethod is perfectly legal and will not trigger some alert (like if you used a method name that’s only used by private calls), so Apple shouldn’t notice it. But I only said shouldn’t, not won’t.