My UITableView cells take content (images) from others cells. I have no idea why that happening, but I am sure that my mistake is silly. At the image below you can see how it looks. Cells on the top take images from the cells on the bottom (facebook and twitter icons).
Here is my code for cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *dictionary = [mainArray objectAtIndex:indexPath.section];
NSArray *array1 = [dictionary objectForKey:@"stuff"];
NSString *cellValue = [array1 objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue; // загаловок клетки
cell.textLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:16];
cell.textLabel.textColor = [UIColor colorWithRed:145/256.0 green:0/256.0 blue:0/256.0 alpha:1.0];
cell.backgroundColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.textLabel.textAlignment = UITextAlignmentLeft;
if (indexPath.section == 0 && indexPath.row == 1)
{
if([[NSUserDefaults standardUserDefaults]boolForKey:@"password"] == YES)
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
switch(indexPath.section)
{
case 2:
{
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
break;
case 3:
{
if (indexPath.row == 0)
cell.imageView.image = [UIImage imageNamed:@"facebook"];
else if (indexPath.row == 1)
cell.imageView.image = [UIImage imageNamed:@"twitter"];
else if (indexPath.row == 2)
cell.imageView.image = [UIImage imageNamed:@"youtube"];
else
cell.imageView.image = [UIImage imageNamed:@"vk"];
}
break;
default:
break;
}
return cell;
}

How can I fix it ?
Cells are reused, so you have to set the imageView of your cells to nil whenever you don’t want an image to appear. Try this: