0

我的应用名称是PropertiesSearch,因此该项目包含以下文件:

PropertiesSearchAppDelegate.h
PropertiesSearchAppDelegate.m
PropertiesSearchViewController.h
PropertiesSearchViewController.m

我在 PropertiesSearchAppDelegate.h 中声明了一个实例变量(ListingNav),如下所示:

#import <UIKit/UIKit.h>

@class PropertiesSearchViewController;

@interface PropertiesSearchAppDelegate : NSObject <UIApplicationDelegate> {
    UINavigationController *ListingNav;
}

@property (nonatomic, retain) UINavigationController *ListingNav;

@end

在 PropertiesSearchAppDelegate.m 中,我添加了

@synthesize ListingNav; 

现在我正在尝试从 PropertiesSearchViewController.m 访问 ListingNav,如下所示:

PropertiesSearchAppDelegate *appDelegate = (PropertiesSearchAppDelegate *)[[UIApplication sharedApplication] delegate];
// Then here I can easily do appDelegate.ListingNav etc...

但调试器显示:

使用未声明的标识符 PropertiesSearchAppDelegate

我应该在 PropertiesSearchViewController.h 中导入 PropertiesSearchAppDelegate.h

提前谢谢您的帮助

斯蒂芬妮

4

1 回答 1

3

您必须在PropertiesSearchViewController.h中导入PropertiesSearchAppDelegate.h

要让一个类知道另一个类,您应该导入该类或添加@class 指令。添加@class 指令只是让类知道存在另一个类。在您的情况下,您应该在尝试访问该类的成员时导入PropertiesSearchAppDelegate 。

于 2011-09-05T11:20:07.393 回答