views:

55

answers:

2

I've tried to overwrite the accessor for -selectedBackgroundView in a custom UITableViewCell subclass. However, the cell keeps using the default blue selection background when the cell is selected. How to change that?

I'm actually pretty sure that this blue selection thing is the selectedBackgroundView ... what else should be responsible for this blue background which has a light gradient? The strange thing though, is that the contentView is above that, and while it has a backgroundColor other than [UIColor clearColor], this selectedBackgroundView still seems to shine through. Really strange.

+3  A: 

Hi

You have to just put this code into "cellForRowAtIndexPath"

For disable the cell select:(While Clicking the cell)

cell.selectionStyle = UITableViewCellSelectionStyleNone;

For enable the cell:(While Clicking the cell)

cell.selectionStyle = UITableViewCellSelectionStyleBlue;(By Default)

cell.selectionStyle = UITableViewCellSelectionStyleGray;

If you want to give your custom colour then in cellForRowAtIndexPath"

if (cell==nil)

{  
 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
 UIView *v = [[[UIView alloc] init] autorelease];
    v.backgroundColor = [UIColor redColor];
    cell.selectedBackgroundView = v;
}

All the best.

Warrior
+1  A: 

Sounds like you simply want to add

self.selectionStyle = UITableViewCellSelectionStyleNone;

to your custom class's init. You can also override the setSelected:animated: method if you want to do any heavy duty handling.

Nicholas M T Elliott