当用户点击一个单元格(突出显示状态)时,我正在尝试更改单元格背景图像,我一直在尝试这种方式,但它不起作用:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentRight;
cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
cell.textLabel.font = [UIFont fontWithName:kFONT_NAME size:kFONT_SIZE];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row320x63.png"] highlightedImage:[UIImage imageNamed:@"row320x63_pressed.png"]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row320x63.png"]];
cell.textLabel.text = [self.listOfMenuSettings objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"settings_icon_%d", indexPath.row]];
UIImageView *pressed = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row320x63_pressed.png"]];
[cell setSelectedBackgroundView:pressed];
return cell;
}
我缺少什么?
答案 0 :(得分:0)
我在Apple文档中找不到setSelectedBackgroundView:
实例方法。但是有一个属性selectedBackgroundView
。
所以试试:
cell.selectedBackgroundView = pressed;