1

How to customize the background/border colors of a grouped table view cell?

After reading this post, i tried to use this solution. Here is my code, in the tableViewDelegate methods:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
   CustomCellBackgroundView *customBackground = [CustomCellBackgroundView alloc];

    [customBackground setBorderColor:[UIColor blackColor]];
    [customBackground setFillColor:[UIColor redColor]];
    [customBackground setPosition:0]; //i'll deal with that later

    [cell setSelectedBackgroundView:customBackground];
    [customBackground release];


    UIImageView* selectedBackgroundCell = [[[UIImageView alloc] initWithFrame:CGRectNull] autorelease];
    [selectedBackgroundCell setImage:[UIImage imageNamed:@"cell_bg_50_hover.png"]];
    [customBackground drawRect:selectedBackgroundCell.frame];

    [cell setSelectedBackgroundView:selectedBackgroundCell];

    //standard background color
    [cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_bg_50.png"]]];
}

But unfortunately it doesn't change anything. Do you know what I am doing wrong ?

Community
  • 1
  • 1
Nielsou Hacken-Bergen
  • 2,606
  • 6
  • 27
  • 37

2 Answers2

1

I believe that whenever make views then you should specify some frame for that. So specify frame CGRectZero for both custom background and background....

Following just work for me when I tested.

    UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    bkview.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView = bkview;

Mohammad
  • 1,636
  • 1
  • 13
  • 17
0

You release customBackground and then you call [customBackground drawRect:selectedBackgroundCell.frame];

So obviously, calling the function on a nil pointer won't do anything.