开发者

Not getting View for "cell.selectedBackgroundView"

I am trying to change my cell image when i click on it. I use the code like below :

cell.backgroundView = [[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView = [[[UIImageView a开发者_如何学Pythonlloc] init] autorelease];

cell.textLabel.textColor = [UIColor colorWithRed:162.0/255.0 green:13.0/255.0 blue:20.0/255.0 alpha:1.0];
cell.textLabel.text = [channelCategories objectAtIndex:indexPath.row];

UIImage * backgroundImage = [UIImage imageNamed:@"topAndBottomRow.png"];
UIImage * selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
cell.backgroundColor = [UIColor clearColor];
UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];

cell.backgroundColor = [UIColor clearColor];
((UIImageView *)cell.backgroundView).backgroundColor = [UIColor clearColor];
((UIImageView *)cell.backgroundView).autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
((UIImageView *)cell.backgroundView).image = backgroundImage;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;

Can any one help me out for this issue? Thank you.


Don't typecast to UIImageView. Allocate another UIImageView object, set its image and then assign UIImageView to cell.backgroundView or cell.selectedBackgroundView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜