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 中绘制它?我的标题标题将是关键“区域”,而表格单元格标记关键“商店”,副标题标记关键“位置”。坐标键将用于在用户点击表格单元格时加载的地图视图上绘制它。

提前致谢!

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

你可以试试这个:

//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 回答
0

You have to create 3 NSDictionary. Dict 1: titles Dict 2: celltexts Dict 3: subtitles

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

Then put it into an array

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

in your titlesForHeaderInSection

headertitle = [titlearray objectAtIndex:indexPath.row];

Do the steps for cell text and subtitle again.

于 2012-10-07T09:42:58.367 回答