0

I have a custom separator in every cell(added it in the IB), I want to delete/hide it based on a specific condition:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier= @"satellite";
    SatellitesCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(!cell) {
        cell =[[SatellitesCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

            }

     if([[arrayofRadios objectAtIndex:indexPath.row] isEqualToString:@""]){
         [cell.separatorImage removeFromSuperview];
         cell.separatorImage = nil;

         }

    cell.satelliteName.text=[arrayofSatellitesName objectAtIndex:indexPath.row];

    return cell;
}

When launching the view, all is okay, but the problem is when scrolling, the separator(the UIImageView) is displaying randomly in every cell.

androniennn
  • 3,117
  • 11
  • 50
  • 107

1 Answers1

2

If I understand you correctly, you want to use the same cell prototype but have it look different based on the data. If this is the case, then I wouldn't remove the separatorImage from the superview, just hide it (eg. cell.separatorImage.hidden = YES;). This way in the else case of that if statement, you can unhide it (eg. cell.separatorImage.hidden = NO;).

Or I suppose, if you have a specific reason for removing it from the superview, then just be sure to create an else statement for that if statement, and add it back to the cell (eg. [cell addSubview:cell.separatorImage];).

Mr. T
  • 12,795
  • 5
  • 39
  • 47