gpt4 book ai didi

ios - uitableviewcell 中的数据重叠

转载 作者:行者123 更新时间:2023-11-29 02:15:31 24 4
gpt4 key购买 nike

我真的不知道我做错了什么。我的字典中有数据,如果满足条件将显示这些数据:

if(incentives[@"extras"][@"1"])
{
//display image and label
}

如果字典中的一个数据满足此条件,我就能成功显示图像和标签。如果我有多个,假设有 2 个数据满足此条件,则数据 1 和数据 2 的图像和标签重叠:

enter image description here

我如何让食物图标和标签只显示在单元格 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现在发生的是,如果我有两个符合条件的数据,单元格会显示符合条件的最后一个数据..

最佳答案

当你调用一个“新的”UITableViewCell 时,你并不总是创建一个新的,你通常是在重用它们。所以当你添加一个 subview 时,你必须在重用单元格时删除它。在您的情况下,我建议像本教程中那样创建一个自定义单元格

https://www.youtube.com/watch?v=uhJCuDX4GsA

关于ios - uitableviewcell 中的数据重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28794666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com