如何将此nsdictionary数据填充到uitableview

时间:2015-07-11 08:01:59

标签: ios iphone swift ios7

如何将此NSDictionary数据填充到UITableView 我想要

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath  

从Dict获取数据的方法

2015-07-11 13:19:50.972 demo[1226:23659] {
posts =     (
            {
        post =             {
            id = 1;
            "school_id" = 1;
            subject = Math;
        };
    },
            {
        post =             {
            id = 2;
            "school_id" = 1;
            subject = Science;
        };
    },
            {
        post =             {
            id = 3;
            "school_id" = 1;
            subject = English;
        };
    },
            {
        post =             {
            id = 5;
            "school_id" = 1;
            subject = Hindi;
        };
    },
            {
        post =             {
            id = 29;
            "school_id" = 1;
            subject = Biology;
        };
    }
);
}

1 个答案:

答案 0 :(得分:0)

尝试这种方式从字典中获取数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // if you use custom cell then use this way code
    FriendSelectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendSelectionCell"];
    // get value from dictionary
     cell.yourlabel.text=[[[[self.dict objectForKey:@"posts"] objectAtIndex:indexPath.row] objectForKey:@"post"] objectForKey:@"id"];
    return cell;
}