我有一個簡單的問題:爲什麼「origineArray」返回(null)?我發現,如果我把所有的代碼放在RootViewController中,但是如果我把它放在AppDelegate中(因爲它在示例代碼中,我不會更好?),它不會識別「根」鍵:來自plist的「Root」密鑰無法從AppDelegate識別?
- (id)init {
self = [super init];
if (self){
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"origine.plist"];
origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
}
return self;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"origine data : %@", origine);
NSArray *origineArray = [origine objectForKey:@"Root"];
NSLog(@"origineArray data : %@", origineArray);
感謝您的幫助
謝謝,我已經得到了我的代碼在AppDelegate其實,你可以從一個plist文件「從」一個筆尖開始你的應用程序?這是從Interface Builder創建的? – Paul
我不相信有一種方法可以從plist文件創建NSDictionary,並在界面構建器中自動進行連接。但是,如果將加載代碼放在委託的awakeFromNib方法而不是init中,則應該適當加載。 – codelark
謝謝,其實我不得不把「NSArray」,而不是「NSDictionary」,因爲「根」是一個數組,我起初沒有看到這個錯誤。無論如何,感謝您的幫助! – Paul