Reputation: 711
I have a custom UITableViewCell (instantiated from XIB) with an image as background. Now I want another image to be the background when the cell is selected (similar to the blue flashing for standard cells). I already tried setting it using setSelectedBackgroundView
in (void)setSelected:(BOOL)selected animated:(BOOL)animated
or even in didSelectRowAtIndexPath
but the background for highlighting wont show up. What am I doing wrong?
Upvotes: 2
Views: 1334
Reputation: 6067
have you tried like below one
Call below Method From the TableView DataSource Method (cellForAtIndexPath)
For Doing the same Task
- (void)setCellBGColorNormalAndSelectedForTableViewCell:(UITableViewCell*)cell cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UIImageView *normalCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[normalCellBG setImage:[UIImage imageNamed:@"box_nonselected.png"]];//Set Image for Normal
[normalCellBG setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:normalCellBG];
UIImageView *selecetedCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[selecetedCellBG setImage:[UIImage imageNamed:@"box_selected.png"]];//Set Name for selected Cell
[selecetedCellBG setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:selecetedCellBG ];
}
Upvotes: 2
Reputation: 2145
You can set selected background view using the XIB
you created for CustomCell
. You just need to take UIImageView
on to the that XIB
(imageview
must have same height as that of CustomCell
) . Now connect the outlet naming "selectedBackgroundView
" for that CustomCell
to the UIImageView
you have taken as a selected background view . Also check whether the selectionStyle
for that CustomCell
is not none .
Upvotes: 1