2016-09-30 45 views
0

我用下面的代碼來嘗試選擇時作出的tableview單元格背景清晰的彩色設置透明完全和它的作品沒有複選框,但是當它是完全不清楚的顏色。的UITableViewCell不能複選框

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
cell.tintColor = [UIColor redColor]; 
UIView *selectionView = [UIView new]; 
selectionView.backgroundColor = [UIColor clearColor]; 
[[UITableViewCell appearance] setSelectedBackgroundView:selectionView]; 

正如您從下圖所見,只能在複選框下清除,而不能在整個單元格中清除。但是,當沒有複選框(不是編輯模式)時,這是完全清楚的。我怎樣才能解決這個問題?提前致謝。

enter image description here

如果我刪除上面的代碼,結果會是這樣。白色背景將覆蓋整個單元格。我不知道爲什麼上面的代碼可以設置複選框下面的區域的背景清晰?

enter image description here

+0

設置selectionView的阿爾法。 –

回答

0

添加此方法

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [cell setBackgroundColor:[UIColor clearColor]]; 
} 
+0

在我的情況下不起作用;它給出了相同的結果。 – SanitLee

0

我已經找到解決方法,我們可以編輯下面的代碼

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    //Add below to line 
    [self.tblContact setAllowsMultipleSelectionDuringEditing:YES]; 
    [self.tblContact setEditing:YES animated:YES]; 
    //tblContact is tableView Outlet 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //ContactTableViewCell is xib file of UITableViewCell 
    static NSString *identifier = @"ContactTableViewCell"; 
    ContactTableViewCell *cell = (ContactTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactTableViewCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
    cell.tintColor = [UIColor redColor]; 
    UIView *selectionView = [UIView new]; 
    selectionView.backgroundColor = [UIColor clearColor]; 
    [[UITableViewCell appearance] setSelectedBackgroundView:selectionView]; 
    cell.backgroundColor = [UIColor clearColor]; 
    return cell; 
} 

Demo

+0

在我的情況下不起作用;它給出了相同的結果。 – SanitLee

+0

請告訴我你的情況很顯然 –

+0

我猜這是因爲另一個類,這是MessegeCell(的UITableView類)坐在我的TableView的頂部,所以我必須做一些事情存在。 – SanitLee

0

需要設置細胞和細胞的清晰的背景「內容查看。

0

怎麼樣選擇樣式設置爲無,而不是藍色的?

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
+0

如果我將其更改爲UITableViewCellSelectionStyleNone,它可以擺脫白色背景,但也查馬克,所以當我點擊什麼,意味着在視覺上發生的表 – SanitLee