UITableViewCellSelectionStyleBlue不起作用

我需要使用单元格select样式的UITableViewCellSelectionStyleBlue 。 但是,无论我设置的风格只显示UITableViewCellSelectionStylegray 。 我正在使用Xcode 5。

这是我的代码:

 -(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellid = @"Table1"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellid]; if (cell==Nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid]; } cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; cell.selectionStyle =UITableViewCellSelectionStyleBlue; cell.imageView.image =[UIImage imageNamed:@"cellbgimg.png"] ; return cell; } 

我能够改变UITableviewSelectionStyleBlue 。 请尝试下面的代码:

 // take a view for the cell... UIView *cellBg = [[UIView alloc] init]; cellBg.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // this RGB value for blue color cellBg.layer.masksToBounds = YES; Cell.selectedBackgroundView = cellBg; 

试试这个…

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; if (cell == nil) { cell = [self tableviewCellWithReuseIdentifier:@"myCell" ForIndexpath:indexPath]; } [self configureCell:cell forIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryNone; [cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; // This one for your cell selection style. return cell; }