2016-05-06 7 views
0

これは通常の課題です。私は現在のプロジェクトでこれを何度もやっており、うまくいきました。私は同じ行のコード行をコピーしました。私のplistデータは辞書に入っていますが、初期化の際にはそれぞれの配列には入っていません。私はinitArraysPlistiOS - plistからデータを抽出できません。

-(void)initArraysPlist{ 
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"trainerProfile" ofType:@"plist"]; 
// Load the file content and read the data into arrays 
NSDictionary *dict1 = [[NSDictionary alloc] initWithContentsOfFile:path1]; 

trainerNames = [dict1 objectForKey:@"Names"]; 
trainerIcons = [dict1 objectForKey:@"Icons"]; 
trainerFactSheet= [dict1 objectForKey:@"Fact Sheet"]; 
trainerFocus = [dict1 objectForKey:@"Focus"]; 
trainerContactInfo= [dict1 objectForKey:@"Contact Info"]; 

}

アイブ氏は数回これを行って、それは現在、私のコードで動作するというメソッドを持っています。すべての値が正しい。私は何度もそれをチェックした。

答えて

0

は、このコードを試してみてくださいするときに

// Read plist from bundle and get Root Dictionary out of it 

NSDictionary *dictRoot = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]]; 

// Your dictionary contains an array of dictionary 
// Now pull an Array out of it. 

NSArray *arrayList = [NSArray arrayWithArray:[dictRoot objectForKey:@"catlist"]]; 

// Now a loop through Array to fetch single Item from catList which is Dictionary 

[arrayList enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { 

    // Fetch Single Item 
    // Here obj will return a dictionary 

    NSLog(@"Category name : %@",[obj valueForKey:@"category_name"]); 
    NSLog(@"Category id : %@",[obj valueForKey:@"cid"]); 
}]; 
0

各行のコメントをお読みくださいにそれが役に立つかもしれません。

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"trainerProfile" ofType:@"plist"]; // **check if your plist is actually added in Bundle.If its there move to second line , if not then add plist in bundle.** 

    NSDictionary *dict1 = [[NSDictionary alloc] initWithContentsOfFile:path1];// **if plist is added in bundle , then check if you are getting value for dict1 . If no then you might be making some mistake in plist structure.** 

可能であればplistを投稿してください。

関連する問題