加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Xcode 8 iOS 10 UITableView问题:从故事板添加的UIImageView正

发布时间:2020-12-14 17:36:04 所属栏目:百科 来源:网络整理
导读:我在我的故事板中有表视图,它一直工作到 Xcode 7.3,在将 Xcode更新为8之后,tableviewcell中添加的图像视图不会第一次呈现,直到您滚动或显式调用reloadData.从故事板添加图像视图. 滚动后 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRow
我在我的故事板中有表视图,它一直工作到 Xcode 7.3,在将 Xcode更新为8之后,tableviewcell中添加的图像视图不会第一次呈现,直到您滚动或显式调用reloadData.从故事板添加图像视图.

enter image description here

滚动后

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;
}

解决方法

经过长时间的打击和试验,它在更新后有效

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

要么您可以使用上下文图形来获取圆形图像但仍需要先前的解决方案

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读