【发布时间】:2012-12-01 03:29:59
【问题描述】:
<pre>
products = (
{
id = 19;
"image_url" = "http://localhost:8888/straightoffer/image/data/1330374078photography.jpg";
name = "Save $240 on your next photo session";
},
{
id = 21;
"image_url" = "http://localhost:8888/straightoffer/image/data/1330373696massage.jpg";
name = "One Hour Massage";
}
);
}
</pre>
以上是我通过json得到的,需要给uitableviews赋值:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSLog(@"行数:%d",[[products objectForKey:@"products"] count]); 返回 [[products objectForKey:@"products"] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 如果(细胞 == 零){ 单元格 = [[UITableViewCell 分配] initWithStyle:UITableViewCellStyleDefault 重用标识符:@“细胞”]; } NSString *currentProductName; currentProductName = [productKeys objectAtIndex:indexPath.row]; NSLog(@"产品名称:%@", currentProductName); [[单元格文本标签] setText:currentProductName]; 返回单元格; }它返回 0 行数,我是 ios 的新手,请帮助我如何将这些值分配给 uitableview。
问候
【问题讨论】:
-
我需要更多信息。这段代码看起来不错。这个故事的数据检索部分出了问题。你能添加你如何填写
products字典的代码吗? -
你能登录
products并告诉我们..?如果products本身就是数组,你可以算对吗? -
products = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];这就是产品的填充方式,并且当我使用第一个有问题的 pre 标签记录内容时
-
检查
numberOfRowsInSection,products是否有值或无 -
numberOfRowsInSection 返回 nil
标签: ios uitableview