Reputation: 97
i really don't know what i am doing wrong here. i have data in my dictionary that will be displayed if the condition is met:
if(incentives[@"extras"][@"1"])
{
//display image and label
}
i am able to display the image and label successfully if one data from the dictionary meets this condition. If i have multiple, lets say 2 datas that met this condition the image and label for data 1 and data 2 overlaps:
how will i make the food icon and label to display only in cell 1..and the uniform icon and label display on cell 2..
here's what i have so far:
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;
}
i tried giving separate labels for each incentive and i still get the same result. any help will be appreciated.. thanks in advance...
UPDATE: i followed the tutorial https://www.youtube.com/watch?v=uhJCuDX4GsA..what happens now, is that if i have two data that meets the criteria, the cell displays the last data that met the criteria..
Upvotes: 0
Views: 45
Reputation: 413
When you call a "new" UITableViewCell you are not always creating a new one, you usually are reusing them. so when you add a subview you have to remove it when reusing the cell. and in your case I recommend creating a custom cell like in this tutorial
https://www.youtube.com/watch?v=uhJCuDX4GsA
Upvotes: 1