我遇到了一個奇怪的問題,即將UITableViewCell添加到另一個TableViewController的tableView,該tableView當前不可見,但之前已加載。該問題是該小區被添加到的tableView但單元格的內容是空白的,一旦我去那個視圖控制器:UITableViewCell的內容當從另一個視圖控制器添加單元格時不可見
的cellForRowAtIndexPath其細胞內容查看所述的tableView的被顯示出來隱形:
- (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];
}
}
此視圖控制器在故事板中使用自動佈局進行佈局。謝謝!
我試過,但它偶爾會出現空白 – Midas