Reputation: 153064
I'm currently writing an iPhone application that uses a UITabBarController with more than 5 Tab Bar Items. Thus, a 'more' tab is automatically generated (like in the YouTube Application). I found out that the corresponding view controller class is UIMoreListController, but I don't have any corresponding .h files. So, my code looks like this:
@class UIMoreListController; // can't use #import since .h file is missing
@implementation SomeUINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([viewController isKindOfClass:[UIMoreListController class]])
... // do something if "more" view is active
This works like a charm. However, the compiler keeps giving me
warning: receiver 'UIMoreListController' is a forward class and corresponding @interface may not exist
Is there a neat way of getting rid of this warning (and this particular warning only)? Again, I can't use #import since no .h file is available.
Upvotes: 2
Views: 2721
Reputation: 185701
Why are you trying to do this? You should not be using any private APIs. There's no guarantee that this class will still be there in the next OS release, and if you assume it is, then that road leads to bugs or even crashes.
Upvotes: 0
Reputation: 5159
So long as you're in the moreNavigationController
's delegate, this should do the trick:
[viewController isEqual:[navigationController.viewControllers objectAtIndex:0]]
By comparison, topViewController
will give you the opposite of what you want. Using objectAtIndex:0
should help avoid any private shenanigans.
Upvotes: 0
Reputation: 8823
If you're just trying to check for the UIMoreListController
class you can access the class variable using the objc-api.
if ([viewController isKindOfClass:NSClassFromString(@"UIMoreListController")])
Then you don't need the #import
or the @class
declaration.
Upvotes: 10
Reputation: 153064
declare it as type id, and if necessary declare a category on NSObject with any of the UIMoreListController specific methods you need to call.
This will not do the trick. All I need is
if ([viewController isKindOfClass:[UIMoreListController class]])
Anyway, you're right about releasing dirty hacks via the App Store. Unfortunately, the Reference is somewhat secretive about those moreNavigationControllers. They tell you that it's just a UINavigationController (which, indeed, it is).
Maybe I should try a different approach to finding out if the viewController is some UIMoreListController. Something like
if ([viewController isEqual:[navigationController topViewController]])
should work, since the UIMoreListController is always the topViewController. (I might be wrong, but I'm gonna try out)
Upvotes: 0
Reputation: 40515
You should not have to declare or #import any of the standard Cocoa Touch classes. UIMoreListController does not look like it's a public class that you should be using at this time, if it was it would be listed in the documentation. The page you linked to is an SDK dump, not everything in it is safe to use if you plan to release your application in the App Store.
With that being said though, you can declare it as type id, and if necessary declare a category on NSObject with any of the UIMoreListController specific methods you need to call.
Upvotes: 0