2015-09-28 57 views
1

我有一個關於靜態單元格的問題。這是我的tableview結構:
http://i.stack.imgur.com/1gq1y.png(我不能發表圖片)UITableView靜態單元格 - 選擇顏色不起作用

細胞背景顏色爲Gray和內容查看背景色爲ClearColor。該單元格不使用自定義UITableViewCell子類。

我在故事板中將Selection設置爲Blue。然而,當我運行它時,輸出爲Gray

我試着用這個代碼做手工在didSelectRowAtIndexPath

currentCell.contentView.backgroundColor = self.view.tintColor; 

但事實證明,這樣的:http://i.stack.imgur.com/Zfatl.png

的標籤單元格不會更改爲白色,並且輔助背景不會更改。請幫忙。非常感謝!

回答

0
Add the following code to your TableView: cellForRowAtIndexPath method. 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

// Write code for create your cell and properties regarding that cell 
//add this line 
    cell.selectionStyle = UITableViewCellSelectionStyleDefault; 
    UIView *bgColorView = [[UIView alloc] init]; 
    bgColorView.backgroundColor = [UIColor blueColor]; 
    [cell setSelectedBackgroundView:bgColorView]; 

return cell; 
} 
+0

它現在可以工作,但是如何在選擇過程中將文本標籤更改爲白色?請注意我的tableview單元格的結構: 單元格 - >內容視圖 - >標籤和圖像 非常感謝 – binsnoel

+0

cell.textlabel does not work – binsnoel

+0

我已經得到它了我設置cell.textlabel.highlightColor = UIColor whitecolor]。謝謝@Tapansinh – binsnoel

0

在cellForRowAtIndexPath方法中添加單元格選擇stylecolor作爲stylenone。

cell.selectionStyle = UITableViewCellSelectionStyleNone; 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

// Write code for create your cell and properties regarding that cell 
//add this line 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
return cell; 
} 
+0

應該不是第一行裏面的方法有很多其他需要的代碼一起? – rmaddy

+0

是的,我只是想說這行應該是這種方法.. – Kavita

+0

@katty,我需要我的選擇風格是藍色 – binsnoel

相關問題