0

私はこのplistを設定しています:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <array>
            <dict>
                    <key>area</key>
                    <string>area1</string>
                    <key>shop</key>
                    <string>shop1</string>
                    <key>location</key>
                    <string>2nd Floor</string>
                    <key>coordinates</key>
                    <string>14.733836,121.058221</string>
            </dict>
            <dict>
                    <key>area</key>
                    <string>area1</string>
                    <key>shop</key>
                    <string>shop2</string>
                    <key>location</key>
                    <string>Ground Floor</string>
                    <key>coordinates</key>
                    <string>14.733836,121.058221</string>
            </dict>
            <dict>
                    <key>area</key>
                    <string>area2</string>
                    <key>shop</key>
                    <string>shop1</string>
                    <key>location</key>
                    <string>2nd Floor</string>
                    <key>coordinates</key>
                    <string>14.656918,121.029795</string>
            </dict>
            <dict>
                    <key>area</key>
                    <string>area2</string>
                    <key>shop</key>
                    <string>shop2</string>
                    <key>location</key>
                    <string>Ground Floor</string>
                    <key>coordinates</key>
                    <string>14.656918,121.029795</string>
            </dict>
        </array>
        </plist>

これをUITableView内にプロットするにはどうすればよいですか?私のヘッダータイトルはキー「area」になり、テーブルセルはキー「shop」にラベルを付け、サブタイトルはキー「location」にラベルを付けます。座標キーは、ユーザーがテーブルセルをタップしたときに読み込まれるマップビューにプロットするために使用されます。

前もって感謝します!

4

3 に答える 3

1
- (UITableViewCell *)tableView:cellForRowAtIndexPath:
NSDictionary *dict = [array objectAtIndex: indexPath.section];
cell.textLabel.text = [dict objectForKey: @"shop"];
cell.detailTextLabel.text = [dict objectForKey: @"location"];

- (NSString *)tableView:titleForHeaderInSection:
NSDictionary *dict = [array objectAtIndex: indexPath.section];
NSString *area = [dict objectForKey: @"area"];
return area;

- (void)tableView:didSelectRowAtIndexPath:
NSDictionary *dict = [array objectAtIndex: indexPath.section];
NSString *coordinates = [dict objectForKey: @"coordinates"];
newViewController.coordinates = coordinates
于 2012-10-15T03:44:51.683 に答える
0

3つのNSDictionaryを作成する必要があります。ディクト1:タイトルディクト2:セルテキストディクト3:字幕

NSDictionary * dictTitles = [[NSDictionary dictionaryWithContentsOfFile:@ "filepathtoyourplist"] valueForKey:@ "Titles"];

次に、それを配列に入れます

NSArray * titleArray = [[NSArray alloc] initWithDictionary:dictTitles];

あなたのtitlesForHeaderInSectionで

headertitle = [titlearray objectAtIndex:indexPath.row];

セルテキストと字幕の手順をもう一度実行します。

于 2012-10-07T09:42:58.367 に答える
0

あなたはこれを試すことができます:

//In your .h file
NSArray *array;

//In your .m file
- (void)viewDidLoad {    
   // Some code...
   NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"plist"];
   array = [NSArray arrayWithContentsOfFile:path];
   // Some code...
}

次に、新しいNSObjectクラスを作成し、セルごとにオブジェクトを初期化します。次に例を示します。

MyClass *newInstance = [[MyClass alloc] init];
newInstance.area = [array objectForKey:@"area"];
newInstance.shop = [array objectForKey:@"shop"];
newInstance.location = [array objectForKey:@"location"];
newInstance.coordinates = [array objectForKey:@"coordinates"];

それが役に立てば幸い :)

于 2012-10-07T10:59:59.267 に答える