0

当用户点击单元格(突出显示状态)时,我正在尝试更改单元格背景图像,我一直在尝试这种方式,但它不起作用:

- (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;
}

我错过了什么?

4

1 回答 1

0

setSelectedBackgroundView:我在苹果文档中找不到实例方法。但是有一个属性selectedBackgroundView

所以试试:

cell.selectedBackgroundView = pressed;
于 2013-06-09T09:39:36.697 回答