Reputation:
How to change uitableview cell background image?
I write this code, it's not working. but I am sure this code some minor mistake.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundView:[UIImage imageNamed:@"selected-bg.png"]];
}
Upvotes: 1
Views: 143
Reputation:
You need to wrap the UIImage
in a UIImageView
before you can set it as a backgroundView
:
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]] autorelease];
[cell setBackgroundView:imageView];
Upvotes: 4
Reputation: 31722
You are passing the incorrect parameter to setBackgroundView:
function of UITableViewCell
.. It expect either instance of UIView
or any instance inherited from UIView
.
UIImageView * myImage = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]];
[cell setBackgroundView:myImage];
[myImage release];
Upvotes: 3