3

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"]];
}
Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
Swapnil
  • 1,858
  • 2
  • 22
  • 49

3 Answers3

2
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.

Alex Rozanski
  • 37,815
  • 10
  • 68
  • 69
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
  • how about tables with multiple sections? if i use the above code, cells that are rounded (the first and last in every section) will have a rectangle on finger over which doesn't look good. – Alex Jun 29 '11 at 11:49
0

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...

MohammedYakub M.
  • 2,893
  • 5
  • 31
  • 42
  • hi,yakub_moriss we 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 Apr 12 '10 at 08:40
0

cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mImage.png"]]