gpt4 book ai didi

ios - UITableViewCell ImageView 不更新

转载 作者:行者123 更新时间:2023-12-01 18:19:17 25 4
gpt4 key购买 nike

我的应用程序中有一个表格 View ,用于与自定义表格 View 单元进行消息传递。这个 tableview 填充了来自 JSON 的数组。如果消息未读,我在单元格中有一个 UIImageView 显示蓝点图像。

这是一些代码:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
messagesArray = [self getMessages];
[messagesTableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"MessagesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

NSDictionary *messagesDictionary = [messagesArray objectAtIndex:indexPath.row];

UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.text = [messagesDictionary objectForKey:@"fromUserName"];

UIImageView *readImage = (UIImageView *)[cell viewWithTag:103];
NSNumber *boolNumber = [messagesDictionary valueForKey:@"readFlag"];
BOOL read = [boolNumber boolValue];

if (!read)
readImage.image = [UIImage imageNamed:@"Message Read Circle"];

return cell;
}

当消息被选中时,我向服务器发送一条消息,让它知道消息已读,但是当我返回时,它仍然有未读图像。如果我在模拟器中退出应用程序并重新加载应用程序,未读图像将从我选择的消息中消失,所以我知道标记为已读消息正在通过。为什么不 [messagesTableView reloadData]工作?

最佳答案

由于表格 View 单元格被重复使用,因此无论如何都应该设置图像,
不仅是read == NO .就像是:

if (read)
readImage.image = [UIImage imageNamed:@"Message Read Circle"];
else
readImage.image = [UIImage imageNamed:@"Message Unread Circle"];

关于ios - UITableViewCell ImageView 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18623631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com