从ios UITABLEVIEW打印特定值

  • 本文关键字:打印 ios UITABLEVIEW ios6
  • 更新时间 :
  • 英文 :

SOffer[26229:c07] current Product: (
{
id = 20;
image = "img2.png";
name = "offer 2";
}
)

我有一个产品,当我通过NSLog打印它时,会产生上面的结果,我需要单独打印这些。以下代码生成此

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];if(cell==nil){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@"cell"];}NSString*currentProductName;currentProductName=[productKeys objectAtIndex:indexPath.row];currentProduct=[products objectForKey:[productKeys objectAtIndex:indexPath.row]];NSLog(@"current Product:%@",currentProduct);//currentProductName=[currentProduct objectForKey:@"image"];//currentProduct=[currentProduct];[[cell-textLabel]setText:currentProductName];返回单元格;}

currentProduct被声明为NSArray,但当我尝试使用objectForKey打印时,它说NSArray没有可见的接口声明选择器objectForKey

objectForKey,我相信它只适用于NSDictionary

NSArray没有键值对。除非currentProduct包含JSON文件,否则您必须首先取出第一个Product的Array对象,并将其分配给NSDictionary,然后在那里您可以使用objectForKey来获取图像值。

类似这样的东西:

// Get the first product object from the NSArray. Assuming you dropped your entire Product values into a NSArray
NSMutableDictionary *prodDict = [currentProduct objectAtIndex:indexPath.section];
NSString *prodID = [prodDict objectForKey:@"id"];
NSString *prodName = [prodDict objectForKey:@"name"];
...

最新更新