UITableViewCell separator line disappears on scroll

Posted by iconso on Stack Overflow See other posts from Stack Overflow or by iconso
Published on 2014-07-06T11:23:52Z Indexed on 2014/08/18 22:20 UTC
Read the original article Hit count: 218

Filed under:
|
|

I'm trying to have a separator cell with a custom image. I did try something like that:

In my cellForRowAtIndexPath:

NSString *cellIdentifier = [NSString stringWithFormat:@"identifier"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}

cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:19];
cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor colorWithRed:128/255.0f green:129/255.0f blue:132/255.0f alpha:1.0f];
cell.backgroundColor = [UIColor whiteColor];

UIImageView *imagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"reaL.png"]];
imagView.frame = CGRectMake(0, cellHeight, cellWidth, 1);
[cell.contentView addSubview:imagView];

switch (indexPath.row) {
    case 0:
        cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"img1.png"] scaledToSize:CGSizeMake(27, 27)];
        cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"route.png"] scaledToSize:CGSizeMake(27, 27)];
        break;
    case 1:
        cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"img.png"] scaledToSize:CGSizeMake(27, 27)];
        cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"money.png"] scaledToSize:CGSizeMake(27, 27)];
        break;
    case 2:
        cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"auto.png"] scaledToSize:CGSizeMake(27, 27)];
        cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"cars.png"] scaledToSize:CGSizeMake(27, 27)];
        break;
    case 3:
        cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"impostazioni.png"] scaledToSize:CGSizeMake(27, 27)];
        cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"impostazioni.png"] scaledToSize:CGSizeMake(27, 27)];
       // cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
        break;
    case 4:
        cell.imageView.image = [self imageWithImage:[UIImage imageNamed:@"info.png"] scaledToSize:CGSizeMake(27, 27)];
        cell.imageView.highlightedImage = [self imageWithImage:[UIImage imageNamed:@"info.png"] scaledToSize:CGSizeMake(27, 27)];
        break;
    default:
        break;
}

return cell;

When I lunch the app everything is good, but when I scroll the the table, or when I select a cell the separator lines disappear. How I can have a permanent custom line separator?

© Stack Overflow or respective owner

Related posts about ios

Related posts about objective-c