我有一个包含项目列表的表格视图。当我单击其中一项时,我希望突出显示背景。我的代码可以正常工作,但颜色会在发布时发生变化,而不是在点击本身上。当用户点击单元格而不是当他/她释放它时,如何突出显示?
这是我的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Navigation logic may go here. Create and push another view controller.
Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIView *v=[[UIView alloc] initWithFrame:cell.frame];
v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]];
cell.backgroundView=v;
cell.title.textColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor1"]];
}
我希望它像按钮一样发生。除此之外还有onClick
UITableView 或 UITableViewCell 的方法didSelectRowAtIndexPath
吗?
编辑
这是我的代码cellForRowAtIndexPath
-(void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIView *v=[[UIView alloc] initWithFrame:cell.frame];
v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]];
cell.selectedBackgroundView=v;
}