4

I have tableviews in my storyboard and it is working till Xcode 7.3, After Updating Xcode to 8, imageviews that are added in tableviewcell are not render first time until you scroll OR explicitly call reloadData. Imageviews are added from storyboard.

enter image description here

After scrolling

enter image description here

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

switch (indexPath.section)
{
    case 0:
    {
        //Cell for group button....
        contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:@"groupCell"];

        //Add group button.....
        UIButton *newBtn = (UIButton*)[contactCell viewWithTag:101];
        [newBtn addTarget:self action:@selector(createGroup:) forControlEvents:UIControlEventTouchUpInside];
        newBtn.userInteractionEnabled = YES;

    }break;

    case 1:
    {
        //Add rest of messageList
        contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:@"ContactCell"];

        [contactCell.mUserNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:USER_NAME_LABEL_SIZE]];
        [contactCell.mMessageLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:MESSAGE_LABEL_SIZE]];
        [contactCell.mTimeLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:TIME_LABEL_SIZE]];
        [contactCell.imageNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:IMAGE_NAME_LABEL_SIZE]];

        contactCell.unreadCountLabel.backgroundColor = [ALApplozicSettings getUnreadCountLabelBGColor];
        contactCell.unreadCountLabel.layer.cornerRadius = contactCell.unreadCountLabel.frame.size.width/2;
        contactCell.unreadCountLabel.layer.masksToBounds = YES;

        //contactCell.mUserImageView.hidden = NO;
        contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
        contactCell.mUserImageView.layer.masksToBounds = YES;

        [contactCell.onlineImageMarker setBackgroundColor:[UIColor clearColor]];

        UILabel* nameIcon = (UILabel*)[contactCell viewWithTag:102];
        nameIcon.textColor = [UIColor whiteColor];

        ALMessage *message = (ALMessage *)self.mContactsMessageListArray[indexPath.row];

        ALContactDBService *contactDBService = [[ALContactDBService alloc] init];
        ALContact *alContact = [contactDBService loadContactByKey:@"userId" value: message.to];

        ALChannelDBService * channelDBService =[[ALChannelDBService alloc] init];
        ALChannel * alChannel = [channelDBService loadChannelByKey:message.groupId];

        if([message.groupId intValue])
        {
            ALChannelService *channelService = [[ALChannelService alloc] init];
            [channelService getChannelInformation:message.groupId orClientChannelKey:nil withCompletion:^(ALChannel *alChannel)
            {
                contactCell.mUserNameLabel.text = [alChannel name];
                contactCell.onlineImageMarker.hidden=YES;
            }];
        }
        else
        {
            contactCell.mUserNameLabel.text = [alContact getDisplayName];
        }

        contactCell.mMessageLabel.text = message.message;
        contactCell.mMessageLabel.hidden = NO;

        if ([message.type integerValue] == [FORWARD_STATUS integerValue])
            contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:@"mobicom_social_forward.png"];
        else if ([message.type integerValue] == [REPLIED_STATUS integerValue])
            contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:@"mobicom_social_reply.png"];

        BOOL isToday = [ALUtilityClass isToday:[NSDate dateWithTimeIntervalSince1970:[message.createdAtTime doubleValue]/1000]];
        contactCell.mTimeLabel.text = [message getCreatedAtTime:isToday];

        [self displayAttachmentMediaType:message andContactCell:contactCell];

        // here for msg dashboard profile pic

        [nameIcon setText:[ALColorUtility getAlphabetForProfileImage:[alContact getDisplayName]]];

        if([message getGroupId])
        {
            [contactCell.onlineImageMarker setHidden:YES];
        }
        else if(alContact.connected && [ALApplozicSettings getVisibilityForOnlineIndicator])
        {
            [contactCell.onlineImageMarker setHidden:NO];
        }
        else
        {
            [contactCell.onlineImageMarker setHidden:YES];
        }

        if(alContact.block || alContact.blockBy)
        {
            [contactCell.onlineImageMarker setHidden:YES];
        }

        BOOL zeroContactCount = (alContact.unreadCount.intValue == 0  ? true:false);
        BOOL zeroChannelCount = (alChannel.unreadCount.intValue == 0  ? true:false);

        if(zeroChannelCount || zeroContactCount)
        {
            contactCell.unreadCountLabel.text = @"";
            [contactCell.unreadCountLabel setHidden:YES];
        }

        if(!zeroContactCount && [alContact userId] && (message.groupId.intValue == 0 || message.groupId == NULL)){
            [contactCell.unreadCountLabel setHidden:NO];
            contactCell.unreadCountLabel.text=[NSString stringWithFormat:@"%i",alContact.unreadCount.intValue];
        }
        else if(!zeroChannelCount && [message.groupId intValue]){
            [contactCell.unreadCountLabel setHidden:NO];
            contactCell.unreadCountLabel.text = [NSString stringWithFormat:@"%i",alChannel.unreadCount.intValue];
        }

        contactCell.mUserImageView.backgroundColor = [UIColor whiteColor];
        if([message.groupId intValue])
        {

            [contactCell.mUserImageView setImage:[ALUtilityClass getImageFromFramworkBundle:@"applozic_group_icon.png"]];
            NSURL * imageUrl = [NSURL URLWithString:alChannel.channelImageURL];
            if(imageUrl)
            {
                [contactCell.mUserImageView sd_setImageWithURL:imageUrl];
            }

            nameIcon.hidden = YES;
        }
        else if(alContact.contactImageUrl)
        {
            NSURL * theUrl1 = [NSURL URLWithString:alContact.contactImageUrl];
            [contactCell.mUserImageView sd_setImageWithURL:theUrl1];
            nameIcon.hidden = YES;
        }
        else
        {
            nameIcon.hidden = NO;
            [contactCell.mUserImageView sd_setImageWithURL:[NSURL URLWithString:@""]];
            contactCell.mUserImageView.backgroundColor = [ALColorUtility getColorForAlphabet:[alContact getDisplayName]];
        }

    }break;

    default:
        break;
    }

    return contactCell;
}
kometen
  • 6,536
  • 6
  • 41
  • 51
Abhishek Thapliyal
  • 3,497
  • 6
  • 30
  • 69

1 Answers1

3

After long hit and trials it worked after updating

dispatch_async(dispatch_get_main_queue(), ^{
 contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
 contactCell.mUserImageView.layer.masksToBounds = YES; 
});

OR you can use context graphics to get circular image But still need a prior solution

Abhishek Thapliyal
  • 3,497
  • 6
  • 30
  • 69