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.hPropertiesSearchAppDelegate.hをインポートする必要がありますか?

あなたの助けのために前もってThx

ステファン

4

1 に答える 1

3

PropertiesSearchViewController.hPropertiesSearchAppDelegate.hをインポートする必要があります。

クラスに別のクラスを知らせるには、クラスをインポートするか、 @class ディレクティブを追加する必要があります。@class ディレクティブを追加すると、クラスは別のクラスが存在することを認識できるようになります。あなたの場合、クラスのメンバーにアクセスしようとしているときに、PropertiesSearchAppDelegateをインポートする必要があります。

于 2011-09-05T11:20:07.393 に答える