2015-09-28 58 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

相关问题