我遇到了一个奇怪的问题,我将UITableViewCell添加到另一个TableViewController的tableView中,该tableView当前不可见但之前已加载。 问题是将单元格添加到tableView,但是一旦我转到该视图控制器,单元格的内容就是空白:
tableView的CellForRowAtIndexPath,其单元格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];
}
}
此视图控制器使用故事板中的自动布局进行布局。谢谢!
答案 0 :(得分:0)
尝试刷新表视图后,将数据添加到数据源中。
答案 1 :(得分:0)
你必须添加此行才能尝试添加 [tableView reloadData];