Background image of selected cell

How to change the background image of a cell when you click on a cell in iphone ???? I tried to follow, but it does not work.

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

    cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
}
+3
source share
3 answers
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];

In the above code snippet, you forgot auto-advertisement; also did you set the table delegate? Set a breakpoint in the method tableview:didselectRowAtIndexpathto check if it is called or not.

By the way, your code seems to be correct.

+2
source

You can change the selection type of a UITableView

using

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

some syntex error in the above code try with the correct syntex

by default it will be blue ...

0
source

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

0

Source: https://habr.com/ru/post/1740268/


All Articles