我真的不知道我在这里做错了什么。 我的词典中有数据,如果符合条件,将会显示:
if(incentives[@"extras"][@"1"])
{
//display image and label
}
如果字典中的一个数据满足此条件,我就能成功显示图像和标签。如果我有多个,让我们说满足这个条件的2个数据,数据1和数据2的图像和标签重叠:
如何制作食物图标和标签,仅在单元格1中显示,并在单元格2上显示统一图标和标签..
这是我到目前为止所拥有的:
if(incentives[@"food"][@"1"])
{
cell2.imgIncentive.image = [UIImage imageNamed:@"icon-food.png"];
NSString *strDescription=incentives[@"food"][@"1"];
NSLog(@"FOOD: %@", strDescription);
cell2.lblIncentive.text=strDescription;
cell2.lblIncentive.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
cell2.lblIncentive.numberOfLines=2;
cell2.lblIncentive.lineBreakMode = NSLineBreakByWordWrapping;
}
if(incentives[@"uniform"][@"1"])
{
cell2.imgIncentive.image = [UIImage imageNamed:@"icon-uniform.png"];
NSString *strDescription=incentives[@"uniform"][@"1"];
NSLog(@"UNIFORM: %@", strDescription);
cell2.lblIncentive.text=strDescription;
cell2.lblIncentive.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
cell2.lblIncentive.numberOfLines=2;
cell2.lblIncentive.lineBreakMode = NSLineBreakByWordWrapping;
}
if(incentives[@"commission"][@"1"])
{
cell2.imgIncentive.image = [UIImage imageNamed:@"icon-commission.png"];
NSString *strDescription=incentives[@"commission"][@"1"];
NSLog(@"COMMISSION: %@", strDescription);
cell2.lblIncentive.text=strDescription;
cell2.lblIncentive.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
cell2.lblIncentive.numberOfLines=2;
cell2.lblIncentive.lineBreakMode = NSLineBreakByWordWrapping;
}
if(incentives[@"transport"][@"1"])
{
cell2.imgIncentive.image = [UIImage imageNamed:@"icon-transport.png"];
NSString *strDescription=incentives[@"transport"][@"1"];
NSLog(@"TRANSPORT: %@", strDescription);
cell2.lblIncentive.text=strDescription;
cell2.lblIncentive.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
cell2.lblIncentive.numberOfLines=2;
cell2.lblIncentive.lineBreakMode = NSLineBreakByWordWrapping;
}
if(incentives[@"extras"][@"1"])
{
cell2.imgIncentive.image = [UIImage imageNamed:@"icon-extras.png"];
NSString *strDescription=incentives[@"extras"][@"1"];
NSLog(@"EXTRAS: %@", strDescription);
cell2.lblIncentive.text=strDescription;
cell2.lblIncentive.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
cell2.lblIncentive.numberOfLines=2;
cell2.lblIncentive.lineBreakMode = NSLineBreakByWordWrapping;
}
我尝试为每个奖励提供单独的标签,我仍然得到相同的结果。 任何帮助将不胜感激.. 提前谢谢......
更新:我现在遵循教程https://www.youtube.com/watch?v=uhJCuDX4GsA..what,如果我有两个符合条件的数据,则单元格会显示符合条件的最后数据。
答案 0 :(得分:1)
当您调用“新”UITableViewCell时,您并不总是创建一个新的UITableViewCell,您通常会重复使用它们。因此,当您添加子视图时,您必须在重用单元格时将其删除。在你的情况下,我建议像本教程中那样创建一个自定义单元格