Objective c 如何禁用前向类编译器警告(未记录的类)

Objective c 如何禁用前向类编译器警告(未记录的类),objective-c,xcode,compiler-construction,Objective C,Xcode,Compiler Construction,我目前正在编写一个iPhone应用程序,它使用一个带有5个以上选项卡栏项的UITabBarController。因此,会自动生成一个“更多”选项卡(如YouTube应用程序中)。 我发现相应的视图控制器类是,但我没有任何相应的.h文件。因此,我的代码如下所示: @class UIMoreListController; // can't use #import since .h file is missing @implementation SomeUINavigationControllerD

我目前正在编写一个iPhone应用程序,它使用一个带有5个以上选项卡栏项的UITabBarController。因此,会自动生成一个“更多”选项卡(如YouTube应用程序中)。 我发现相应的视图控制器类是,但我没有任何相应的.h文件。因此,我的代码如下所示:

@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
这很有魅力。然而,编译器一直给我

警告:接收器“UIMoreListController”是转发类,相应的@interface可能不存在


有没有一种巧妙的方法来消除这个警告(而且只限于这个特别的警告)?同样,我无法使用,因为没有可用的.h文件。

您不必声明或导入任何标准的Cocoa Touch类。UIMoreListController看起来不像是您此时应该使用的公共类,如果是,它将在文档中列出。您链接到的页面是SDK转储,如果您计划在App Store中发布应用程序,则并非所有页面都可以安全使用

尽管如此,您可以将其声明为类型id,如果需要,还可以使用需要调用的任何特定于UIMoreListController的方法在NSObject上声明一个类别

将其声明为类型id,并在必要时使用需要调用的任何UIMoreListController特定方法在NSObject上声明一个类别

这是行不通的。我只需要

if ([viewController isKindOfClass:[UIMoreListController class]])
无论如何,你通过应用商店发布肮脏的黑客是对的。不幸的是。他们告诉你它只是一个UINavigationController(确实是这样)

也许我应该尝试另一种方法来确定viewController是否是某个UIMoreListController。差不多

if ([viewController isEqual:[navigationController topViewController]])

应该可以工作,因为UIMoreListController始终是topViewController。(我可能错了,但我会尝试一下)

如果您只是尝试检查
UIMoreListController
类,您可以使用objc api访问该类变量

if ([viewController isKindOfClass:NSClassFromString(@"UIMoreListController")])

那么您就不需要
#import
@class
声明了。

为什么要这样做?您不应该使用任何私有API。不能保证该类在下一个操作系统版本中仍然存在,如果您认为它存在,那么这条路就会导致错误甚至崩溃。

只要您是
moreNavigationController
的委托,这应该可以做到:

[viewController isEqual:[navigationController.viewControllers objectAtIndex:0]]

相比之下,
topViewController
将提供与您所需相反的功能。使用
objectAtIndex:0
应该有助于避免任何私人恶作剧。

你完全正确。毕竟,我决定使用一种不同的方法:我希望这足以检测UIMoreListController。