繁体   English   中英

从另一个视图控制器添加单元格时,UITableViewCell的内容不可见

[英]Content of UITableViewCell Invisible when cell is added from another view controller

我遇到一个奇怪的问题,即将UITableViewCell添加到当前不可见但先前已加载的另一个TableViewController的tableView中。 问题是该单元格已添加到tableView中,但是一旦我转到该视图控制器,该单元格的内容将为空白:

在此处输入图片说明

这是添加单元格的方式: 在此处输入图片说明

tableView的CellForRowAtIndexPath,其cell contentView显示为不可见:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

          LYRConversation *conversation = [_dataSource objectAtIndex:indexPath.row];

          ConversationListCell *cell = (ConversationListCell *)[tableView dequeueReusableCellWithIdentifier:CELL_REUSE_ID forIndexPath:indexPath];

          [self configureCell:cell atIndexPath:indexPath conversation:conversation];

          return cell;

 }

-(void)configureCell:(ConversationListCell *)conversationCell atIndexPath:(NSIndexPath *)indexPath conversation:(LYRConversation *)conversation
{
    [conversationCell updateAvatarWithUrl:[NSURL URLWithString:[self avatarStringUrlForConversation:conversation]]];
    [conversationCell updateTitle:[self titleForConversation:conversation]];
    [conversationCell updateUnreadMessageIndicator:conversation];
    NSArray *otherParticipants = [[PersistentCache sharedCache] cachedUsersForUserIDs:conversation.participants];
    conversationCell.preview.text = [((PFUser *)otherParticipants.lastObject) objectForKey:@"jobTitle"];
    [UIView updateStatusIndicatorOfConversation:otherParticipants statusIndicator:conversationCell.status];
}


-(void)updateAvatarWithUrl:(NSURL *)avatarUrl
{
    if (avatarUrl != nil) {
        downloadImageThenSetForImageView(self.avatar, avatarUrl);
    }
}

-(void)updateTitle:(NSString *)title
{
    self.title.text = title;
}

-(void)updateUnreadMessageIndicator:(LYRConversation *)conversation
{
    if (conversation.lastMessage.isUnread) {
        [_unreadMessageIndicator setImage:[ConversationListCell unreadBlue]];
    }
    else {
        [_unreadMessageIndicator setImage:[ConversationListCell unreadGray]];
    }
}

+(void)updateStatusIndicatorOfConversation:(NSArray<PFUser *> *)users statusIndicator:(UIView *)view
{
    int  statusValue = ((NSNumber *)[users.firstObject objectForKey:@"status"]).intValue;
    if (statusValue == 1) {
        view.backgroundColor = [UIColor PNGInOffice];
    }
    else if(statusValue == 2){
        view.backgroundColor = [UIColor PNGBusy];
    }
    else if(statusValue == 3){
        view.backgroundColor = [UIColor PNGAway];
    }
}

该视图控制器使用情节提要中的自动布局进行布局。 谢谢!

将数据添加到数据源后,尝试刷新表视图。

您必须添加此行将可以尝试添加[tableView reloadData];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM