0

我有一个聊天应用程序,我想在其中显示在线成员和离线成员。现在我为在线会员添加一个绿点,像这样的单元格图像:

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我所拥有的图像。谁能告诉我我该怎么做?

4

2 回答 2

1

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

  1. 检查用户是在线cellForRowAtIndexPath:还是离线,并根据该图像将图像分配给 imageView。
  2. 当任何用户离线时,只需使用重新加载您的表格视图[yourTableView reloadData];
于 2012-10-15T10:35:43.690 回答
0
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];

此代码应将单元格图像更改为红色图像。对于要更改的单个单元格图像(即,如果不需要单元格数组),请删除 for 循环并更改
NSIndexPath *indexPath = [cellArray objectAtIndex:0];

于 2012-10-15T10:38:52.753 回答