Ios 如何从另一个函数更新cellimages?

Ios 如何从另一个函数更新cellimages?,ios,uitableview,Ios,Uitableview,我有一个聊天应用程序,我想在其中显示在线成员和离线成员。现在我为在线会员添加了一个绿点,如下图所示: UIImage *cellImage = [UIImage imageNamed:@"green.png"]; cell.imageView.image = cellImage; [cell.imageView setTag:102]; //NSStringEncoding encoding=NSASCIIStringEncoding; cell.imageView.frame=CGRectMa

我有一个聊天应用程序,我想在其中显示在线成员和离线成员。现在我为在线会员添加了一个绿点,如下图所示:

UIImage *cellImage = [UIImage imageNamed:@"green.png"];
cell.imageView.image = cellImage;
[cell.imageView setTag:102];
//NSStringEncoding encoding=NSASCIIStringEncoding;
cell.imageView.frame=CGRectMake(0,0,13,13);
cell.imageView.bounds=CGRectMake(0,0,13,13);
[cell.imageView setClipsToBounds:NO];
现在,当用户脱机时,我想将此图像更改为红色。现在,我正在从表视图中删除脱机用户,如下所示,在触发函数中:

[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[channel.memberIDs indexOfObject:memberID] inSection:0]]
                      withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];

但现在我不想执行删除过程。我想将图像更改为我正在使用的
red.png
。有人能告诉我怎么做吗?

这可以通过以下方式实现:

  • cellforrowatinexpath:
    中,检查用户是在线还是离线,并根据该设置将图像分配给imageView
  • 当任何用户脱机时,只需使用
    [yourTableView reloadData]重新加载表视图即可
  • NSArray*cellArray=(NSArray*)[[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[channel.memberIDs indexOfObject:memberID]分区:0]];
    对于(int i=0;i<[光线计数];i++){
    NSIndexPath*indexPath=[X]对象索引:i];
    UITableViewCell*cell=[self.tableView cellForRowAtIndexPath:indexPath];
    UIImage*cellImage=[UIImage ImageName:@“red.png”];//图像更改为红色
    cell.imageView.image=cellImage;
    }
    [self.tableView重载数据];
    
    此代码应将单元格图像数组更改为红色图像。对于要更改的单个单元格图像(即,如果不需要单元格数组),请删除For循环并更改

    nsindepath*indepath=[carlaray objectAtIndex:0]

    是否尝试使用[self.tableView reloadData];?尝试在一个字符串中选择图像名称。并将其交给映像。每次重新加载表时,该映像名称都将被还原。我有一个方法检查用户是否联机。该方法在用户脱机时触发。在该方法中,我执行了deleterow方法。但我想更新我要问的单元格映像?
    NSArray *cellArray = (NSArray *) [[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[channel.memberIDs indexOfObject:memberID] inSection:0]] ];
    
        for (int i = 0 ;i < [cellArray count] ;i++) {
            NSIndexPath *indexPath = [cellArray objectAtIndex:i];
    
            UITableViewCell *cell = [ self.tableView cellForRowAtIndexPath:indexPath];
    
             UIImage *cellImage = [UIImage imageNamed:@"red.png"]; //image changed to red
            cell.imageView.image = cellImage;
    
        }
    
    [self.tableView reloadData];