views:

135

answers:

2

How to change cell background image on click on cell in iphone????I have tried following but it is not working....

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,320,50) reuseIdentifier:myid] autorelease];

    cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
}
A: 
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];

In the above piece of code you forget to autorelease; also have you set the delegate of the tableview? Set a breakpoint on the tableview:didselectRowAtIndexpath method to check if it is called or not.

BTW your code seems right.

Rahul Vyas
Thanks for reply...my code is working now...
iSwap
A: 

hi,Rahul

You can change the selectionType of UITableView

using

cell.setSelectionStyle = [UITableViewSelectionStyleGray/Blue/None] (only 3 types)

some syntex error in above code try with proper syntex

by default it will be blue...

yakub_moriss
hi,yakub_morisswe can also create selection color of any type. Using a view as selected BackgroundView. BTW i know how to chnage selection of UITableViewCell. Thanks for comments
Rahul Vyas