UITableView静态单元格 - 选择颜色不起作用
问题描述:
我有一个关于静态单元格的问题。这是我的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
的标签单元格不会更改为白色,并且辅助背景不会更改。请帮忙。非常感谢!
答
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;
}
答
在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;
}
答
注意,在IOS 7,使用
[细胞setSelectionStyle:UITableViewCellSelectionStyleBlue];
将无法按预期工作,因为在iOS 7中这现在是灰色的,即使 您通过上述常数。请参阅:
韦恩Jensen的答案: https://stackoverflow.com/a/19257253/2575115
它现在可以工作,但是如何在选择过程中将文本标签更改为白色?请注意我的tableview单元格的结构: 单元格 - >内容视图 - >标签和图像 非常感谢 – binsnoel
cell.textlabel does not work – binsnoel
我已经得到它了我设置cell.textlabel.highlightColor = UIColor whitecolor]。谢谢@Tapansinh – binsnoel