Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获取UITAbleViewCell高亮显示状态以更改单元格背景?_Ios_Uitableview_Background_Highlight - Fatal编程技术网

Ios 如何获取UITAbleViewCell高亮显示状态以更改单元格背景?

Ios 如何获取UITAbleViewCell高亮显示状态以更改单元格背景?,ios,uitableview,background,highlight,Ios,Uitableview,Background,Highlight,我试图在用户点击单元格时更改单元格背景图像(高亮显示状态),我一直在尝试这种方式,但不起作用: - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detai

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

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

我缺少什么?

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


所以请尝试:

cell.selectedBackgroundView = pressed;

图像的名称是否正确?我尝试了一个示例来检查这一点,我需要设置backgroundView,并仅在
单元格中选择backgroundView for RowatinePath:
only。没有别的了。它是开箱即用的。
selectedBackgroundView
是一个属性,因此它可以用两种方式设置,没有区别。@IDANMOHER当您选择一个单元格时,通过调试此方法中设置为单元格背景属性的内容来检查:
-(void)tableView:(UITableView*)tableView DidSelectRowatineXpath:(NSIndexPath*)indexPath{}
我正在DidSelectRowatineXpath中做一些事情,因此我知道DidSelectRowatineXpath没有出错。@我建议她检查一下,以便您知道背景是零还是什么。