My app name is PropertiesSearch so the project contains the following files:
PropertiesSearchAppDelegate.h
PropertiesSearchAppDelegate.m
PropertiesSearchViewController.h
PropertiesSearchViewController.m
I declared an instance variable (ListingNav) in PropertiesSearchAppDelegate.h like this:
#import <UIKit/UIKit.h>
@class PropertiesSearchViewController;
@interface PropertiesSearchAppDelegate : NSObject <UIApplicationDelegate> {
UINavigationController *ListingNav;
}
@property (nonatomic, retain) UINavigationController *ListingNav;
@end
and in PropertiesSearchAppDelegate.m, I added
@synthesize ListingNav;
Now I'm trying to access ListingNav from PropertiesSearchViewController.m like this:
PropertiesSearchAppDelegate *appDelegate = (PropertiesSearchAppDelegate *)[[UIApplication sharedApplication] delegate];
// Then here I can easily do appDelegate.ListingNav etc...
But debugger is showing:
Use of undeclared identifier PropertiesSearchAppDelegate
Should I import PropertiesSearchAppDelegate.h in PropertiesSearchViewController.h ?
Thx in advance for your help
Stephane
You have to import PropertiesSearchAppDelegate.h in PropertiesSearchViewController.h .
To let a class know about another class, you should either import the class or add @class directive . Adding @class directive just lets the class aware that another class exists. In your case, you should import PropertiesSearchAppDelegate as you are trying to access the members of the class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.