0

我有一个数组,如下所示

MutableArray (
        {
        "a" = 1;
        "b" = "";
        "c" = " ";
        "imagepath" = "../images/image.png";
        "d" = "dummy text";
        "e" = 2;
        "f" = "dummy text";
        "g" = dummy text;
        "h" = dummy text;
        "i" = "Feb 19, 2010";
    },
        {
        "a" = 2;
        "b" = "dummy";
        "c" = "dummy";
        "imagepath" = "../images/noimage.png";
        "d" = "dummy text";
        "e" = 3;
        "f" = "dummy text";
        "g" = dummy text;
        "h" = dummy text;
        "i" = "Mar 23 , 2010";
    })

我到底在尝试的是从数组中分别获取值,例如

row 1 : Title a,
row 2 : Title b,
row 3 : title c,

我想要数组中的每个值分别。

我有表格视图,自定义单元格,已经创建了图像和标签。例如,第 1 行 = 来自索引 1 的数据第 2 行 = 来自索引 2 的数据,类似这样。我不确定如何从数组中获取分隔值并将其放入表格行的标签中。

请建议,我该怎么做。

4

2 回答 2

1

如果是数组,为什么不直接在cellForRowAtIndexPath方法中使用[objectAtIndex:indexPath.row]来构建tableView呢?您还可以创建一个单元格对象,并使数组成为这些对象的数组,然后从中提取值。

于 2012-06-18T13:18:27.223 回答
1

// 尝试使用 KVC 获取值

// 粘贴到 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    id key;
    NSDictionary *theDictionary = [yourMutableArray objectAtIndex:indexPath.row];
    id value;
    for (key in [theDictionary allKeys])
    {
        value = [theDictionary objectForKey:key];
        // do something with the value
    NSLog(@"key: %@, value: %@", key, [theDictionary objectForKey:key]);
    }
Or else Try this

NSDictionary *theDictionary = [yourMutableArray objectAtIndex:indexPath.row];
NSLog(@"key: a, value: %@", , [theDictionary objectForKey:@"a"]);
NSLog(@"key: b, value: %@", , [theDictionary objectForKey:@"b"]);
NSLog(@"key: c, value: %@", , [theDictionary objectForKey:@"c"]);
// So on ...
于 2012-06-18T13:21:19.610 回答