2011-07-18 17 views
1

ここに私の問題です、私はセルに私のplistの名前を表示することができるUITableViewを作成しようとしています。私はPlistの名前を得ることができません。私は情報を抽出するために必要なプログラミングコードではあまり確かではないと思う。Xcodeを使用して辞書の配列を持つ私のPlistを読み書きします

あなたが良いチュートリアルやサンプルコードを提供することによって助けになるなら、素晴らしいだろう。ありがとう!

<array> 
    <dict> 
     <key>Name</key> 
     <string>Device 2</string> 
    </dict> 
    <dict> 
     <key>Name</key> 
     <string>Device 1</string> 
    </dict> 
</array> 

これらのコードは私のtableViewで

NSBundle *bundle = [NSBundle mainBundle]; 

    NSString *path = [bundle pathForResource:@"devicelist" ofType:@"plist"]; 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    if ([fileManager fileExistsAtPath:path]) { 
     NSLog(@"The file exists"); 
    } else { 
     NSLog(@"The file does not exist"); 
    } 

    contentDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
    NSLog(@"The count: %i", [contentDict count]); 
    contentArray = [NSMutableArray arrayWithContentsOfFile:path]; 
    NSLog(@"The array: %i", [contentArray count]); 
    [contentArray retain]; 
    [contentDict retain]; 
    [mainTableView reloadData]; 

及びこれらの..私のviewDidLoadで..です

static NSString *MyIdentifier = @"MyIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]autorelease]; 
    } 

    cell.textLabel.text = [sortedArray objectForKey:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    return cell; 

答えて

4

たぶん、あなたはのviewDidLoadで以下試してみたい:

NSBundle *bundle = [NSBundle mainBundle]; 

    NSString *path = [bundle pathForResource:@"devicelist" ofType:@"plist"]; 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    if ([fileManager fileExistsAtPath:path]) { 
     NSLog(@"The file exists"); 

    self.contentArray = [NSMutableArray arrayWithContentsOfFile:path]; 
    NSLog(@"The array: %i", [contentArray count]); 

    [mainTableView reloadData]; 
} 

コンテンツに気付くだけですアレイは、cellForRowAtIndexPathメソッドでとプロパティを保持する必要があります。このことができます

NSDictionary *dict = [self.contentArray objectAtIndex:indexPath.row]; 
cell.textLabel.text = (NSString*)[dict objectForKey:@"Name"]; 

希望...私は今それを持っている

+0

ありがとう! :) – AlwynIsPat

関連する問題