1

我是新手,所以请不要打我谢谢...我有以下字典

           NSMutableArray *array;
           NSDictionary *dict,*dict1;

viewdidload 方法

           array=[NSMutableArray array];
           dict=[NSDictionary dictionaryWithObjectsAndKeys:@"12.00",@"Tomato"];
           [array addObject:dict];

           dict1=[NSDictionary dictionaryWithObjectsAndKeys:@"75.00",@"Cauliflower"];
           [array addObject:dict1];

我想以 uitableview 格式显示以下项目

番茄 12.00

花椰菜 75.​​00

4

1 回答 1

3

像这样创建数据。

   array=[NSMutableArray array];
   dict=[NSDictionary dictionaryWithObjectsAndKeys:@"12.00",@"price",@"Tomato",@"name", nil];
   [array addObject:dict];

  dict1=[NSDictionary dictionaryWithObjectsAndKeys:@"75.00",@"price",@"Cauliflower",@"name", nil];
   [array addObject:dict1];

然后显示在您的 tableView 上

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] ;
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@  %@",[[array objectAtIndex:0]objectForKey:@"name"],[[array objectAtIndex:0]objectForKey:@"price"] ];
  return cell;
}
于 2012-08-24T09:47:13.463 回答