我發現了selectedBackgroundView
屬性。我使用這種方法,而不是setSelected: animated:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackground" ofType:@"png"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundImagePath];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.frame = self.bounds;
NSString *selectedBackgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackgroundDark" ofType:@"png"];
UIImage *selectedBackgroundImage = [UIImage imageWithContentsOfFile:selectedBackgroundImagePath];
self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:selectedBackgroundImage] autorelease];
self.selectedBackgroundView.frame = self.bounds;
return self;
}
我不知道這是否是正確的方法,因爲它引入了一些其他問題。有一件事是單元selectionStyle
必須是UITableViewCellSelectionStyleNone
以外的東西,否則它不會顯示背景圖像。取消動畫也停止了。我會開一個關於這些問題的新問題。
感謝您的回答。這是我正在嘗試的,但我必須手動處理取消選擇。 – 2010-03-12 02:33:42