0

我有数组并将所有值保存在 arraypartno 中,我将该特定值放在标签中,并希望在我的单元格中显示,如 PARTNUMBER:-

这是代码: -

 for (int i =0 ; i<[arrData count]; i++)


   {    
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"Condition"]];
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"DateCode"]];
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"MFG"]];
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"PARTNUMBER"]];
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"Qty"]];
        [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"id"]];
    }

所以我必须在 lblplate1.text 中为特定键写什么,现在它显示整个数组值。

UILabel *lblplate1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 200, 30)];

lblplate1.text = [arraypartno  objectAtIndex:indexPath.row];
lblplate1.textColor = [UIColor colorWithRed:2.0/255.0 green:143.0/255.0 blue:213.0/255.0 alpha:1];

lblplate1.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:lblplate1];
4

2 回答 2

1

如果您正在为客户端应用程序工作,请尝试采用MVC。通过以具有条件、日期代码、MFG、Partno 等属性的模型对象的形式存储数据,并将数据存储在模型对象数组中

for (int icounter=0; icounter<[arrData count]; icounter++) {
                    if (objModalClass!=nil) {
                        [objModalClass release];
                        objModalClass=nil;
                    }
                    objModalClass=[[ModalClass alloc]init];
                    objModalClass.Condition=[[arrData objectAtIndex:i] valueForKey:@"Condition"];
                    objModalClass.DateCode=[[arrData objectAtIndex:i] valueForKey:@"DateCode"];;
                    objModalClass.partno=[[arrData objectAtIndex:i] valueForKey:@"PARTNUMBER"];
                    [arrList addObject:objModalClass];
                }
}

从模型类对象中检索数据

for (ModalClass *obj in arrList){
           lblCondition.text=obj.Condition;
}

尝试使用 MVC,因为如果您必须添加新属性或删除它们,您可以轻松更改结构。

于 2013-02-19T13:58:37.140 回答
0

不要将不同的键值添加到同一个数组,而是为不同的键创建不同的数组

像这样

    [arrayCondition addObject:[[arrData objectAtIndex:i] valueForKey:@"Condition"]];
    [arrayDateCode addObject:[[arrData objectAtIndex:i] valueForKey:@"DateCode"]];
    [arrayMFG addObject:[[arrData objectAtIndex:i] valueForKey:@"MFG"]];
    [arraypartno addObject:[[arrData objectAtIndex:i] valueForKey:@"PARTNUMBER"]];
    [arrayQty addObject:[[arrData objectAtIndex:i] valueForKey:@"Qty"]];
    [arrayID addObject:[[arrData objectAtIndex:i] valueForKey:@"id"]];

并在 cellforRowAtIndexPath

lblplate1.text = [arraypartno  objectAtIndex:indexPath.row];

注意:- 请在 viewDidLoad 中初始化数组。

于 2013-02-19T11:27:55.343 回答