【发布时间】:2013-09-04 20:56:48
【问题描述】:
我的应用中有一个表格视图,用于与自定义表格视图单元进行消息传递。这个 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] 不起作用?
【问题讨论】:
-
你什么时候更新
messagesArray来设置readFlag? -
在
viewDidAppear。当我从消息中返回此 tableview 时不会调用它吗? -
我的猜测(最好我能提供所提供的信息)是您在服务器更新有机会完成之前调用
reloadData。您是否正在更新服务器信息,然后成功重新加载表? -
如果您的消息处于模式视图中,则不会调用
viewDidAppear。 -
@MikeZ - 我有一个推送过渡。而且,我在 tableview 上有一个 UIRefreshControl。如果有任何新消息,它会更新 tableview,所以我知道服务器有时间刷新。如果它被标记为已读,它不会更新 uiimageview。
标签: ios objective-c json uitableview uiimage