起動時にAppDelegateでオブジェクトのオブジェクトを初期化する必要があります。他の場所でivarにアクセスしようとすると、返されるものはすべてnullになります。
私がしていることは次のように単純化することができます
//AppDelegate.h:
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
NSString* someString;
}
@property (nonatomic, copy) NSString* someString;
そしてAppDelegate.mで
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
someString = @"Hello World!";
NSLog(@"%@",someString);
}
これは、NSStringオブジェクトにアクセスするときに行うことです。
//ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@",delegate.someString);
}
出力テキストは
- 2012-09-30 22:26:45.125 Labor3 [22524:f803] Hello World!
- 2012-09-30 22:26:45.127 Labor3 [22524:f803](null)
警告やエラーなしで。
私が抱えている問題はもう少し複雑ですが、本質は同じままであり、上記の例を機能させることさえできません。ヒントをいただければ幸いです。