2014-02-21 45 views
0

在以下任何一種方法中設置backgroundView和selectedBackgroundView似乎都不起作用。設置UITableViewCell backgroundView和selectedBackgroundView在iOS7中不起作用

UIView * bSg = [[UIView alloc] init]; 
UIView * bg = [[UIView alloc] init]; 
UIImageView *topSImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgActive"]]; 
UIImageView *topImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]]; 
[bg addSubview:topImage]; 
[bSg addSubview:topSImage]; 
self.backgroundView = bg; 
self.selectedBackgroundView = bSg; 

試過在所有這些細胞的方法

- (void)layoutSubviews 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
- (id)init 

放在layoutSubviews當它工作第一次加載的時候,卻選擇細胞時沒有發生(又名selectedBackgroundView未設置)設置。

是的,我已經在layoutSubviews設置self.backgroundColor = [UIColor clearColor]清除iOS7白色

回答

1
+0

所以這個問題是這樣的tableview類從通過設置其細胞中的類繼承類方法(+)。然後我的tableview甚至沒有使用cellForRowAtIndex方法,不知道爲什麼他們這樣構建它。經過幾個小時的代碼篩選之後,我發現了被調用的cellForRowAtIndex,並修改了它。以下需要實現(cell.selectionStyle = UITableViewCellSelectionStyleDefault;) – jdog

2

這裏是我的代碼來設置背景圖像細胞表視圖:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ... 
    //set cell background 
    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shopsCellBackground"]]; 
    background.backgroundColor = [UIColor clearColor]; 
    background.opaque = NO; 
    cell.backgroundView = background; 
    ... 
} 

我相信,你的關鍵是在tableView:cellForRowAtIndexPath表格視圖方法中爲單元格中的單元格設置背景圖像和選定的背景圖像。

相關問題