繁体   English   中英

UICollectionViewCells重叠

[英]UICollectionViewCells overlapping

我正在使用UICollectionView在我的应用程序中显示数据。 现在的问题是,当我滚动视图时,有时单元格位置不会保持稳定。 它们开始彼此重叠。 我检查了下面方法提供的值。 他们是正确的。 这是我的代码:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

我正在使用默认布局,

self.collectionView.collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];

有人认为我注意到UICollectionViewCell并未根据UICollectionView宽度调整大小![uicollectionView单元重叠] [2]

如您在附件图像中所见,集合视图的背景色(红色)并不位于完整的UICollectionViewCell的背面。 需要一些指导。

谢谢。

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {


UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

cell.backgroundColor = [UIColor whiteColor];

Post *post=[_fetchedResultsController objectAtIndexPath:indexPath];

LoungeUserPostCell *loungepostcell=(LoungeUserPostCell *)cell;

if (indexPath.row==1)
{
    loungepostcell.userPostedText.text=post.chat_msg;

    loungepostcell.lblPostTime.text=@"";
    loungepostcell.lblUsername.text=[NSString stringWithFormat:@"userid =%@", post.user_id];
}
else
{
    if (post.chat_img_medium !=nil || post.chat_img_full!=nil)
    {
        //            CGRect chat_msg_rect=CGRectFromString(post.chat_msg_rect);
        [loungepostcell willHaveImage:YES imageRect:CGRectMake(10, [post.height floatValue]-kPostImageHeight, kPostImageWidth, kPostImageHeight)];

        if (post.chat_img_medium!=nil) {
            [loungepostcell.userPostedImage setImageWithURL:[NSURL URLWithString:post.chat_img_medium] placeholderImage:[UIImage imageNamed:@"G-story.png"]];
        }
        else
            [loungepostcell.userPostedImage setImageWithURL:[NSURL URLWithString:post.chat_img_full] placeholderImage:[UIImage imageNamed:@"G-story.png"]];

    }
    else
    {
        [loungepostcell willHaveImage:NO imageRect:CGRectZero];
    }
    loungepostcell.userPostedText.text=post.chat_msg;
    loungepostcell.lblPostTime.text=[[[Shared instance]dateFormateForLosAngeles]stringFromDate:post.chat_time];
    loungepostcell.lblUsername.text=[NSString stringWithFormat:@"%@", post.user_detail.user_name];
}


return cell;

}

在此处输入图片说明

我发现了问题,问题出在单元格中,因为我使用的是笔尖,所以我将整个视图添加为子视图。 我这样做是因为我也想使用nib和UICollectionViewCell类。

[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"LoungeUserPostCell" owner:self options:nil]objectAtIndex:0]];

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
       // Initialization code
       self.backgroundColor=[UIColor orangeColor];

       [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"LoungeUserPostCell" owner:self options:nil]objectAtIndex:0]];

       [self onLoadAdjustments];
    }
    return self;
}

现在,我在“集合”视图中将其注册为笔尖,并使用- (void)awakeFromNib方法更改笔尖。

暂无
暂无

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

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