我想用我的AppDelegate来存储一个对象,这将是任何其他类访问。 我宣布这个AppDelegate中是这样的:
@interface MyAppDelegate : UIResponder <UIApplicationDelegate>
{
MyClass *tracker;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ICViewController *viewController;
@property (retain, nonatomic) MyClass *tracker;
@end
我综合跟踪和应用中:didFinishLaunchingWithOptions:我在像这样的对象设置一个NSString的:
self.tracker = [[MyClass alloc] init];
self.tracker.testGlobal = @"global funguje";
当我需要到别的地方访问跟踪器在其它的类我用这个代码:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
MyClass *trackerTEST = appDelegate.tracker;
NSLog(@"TEST : %@",trackerTEST.testGlobal);
问题是,testGlobal为NULL。 我究竟做错了什么? 另外这里是MyClass的类文件:
@interface MyClass : NSObject
{
NSString *testGlobal;
}
@property (retain, nonatomic) NSString *testGlobal;
@end
@implementation MyClass
@synthesize testGlobal = _testGlobal;
@end
感谢任何形式的帮助!