打破数组,进入表格视图

时间:2012-06-18 13:11:50

标签: iphone arrays ipad

我有一个数组,如下所示

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的数据  类似的东西。 我不确定如何从数组中获取分隔值并将其放在表格行的标签中。

请建议,我该怎么做。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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 ...