gpt4 book ai didi

ios:在 Collection View 单元格中重叠图像

转载 作者:行者123 更新时间:2023-11-29 12:23:45 24 4
gpt4 key购买 nike

我以编程方式创建了 Collection View ,其中我以编程方式在 collectionViewCell 中创建了 UIImageview,并且 ImageView 中显示的图像是从服务器异步下载的。

下面的代码写在 cellForItemAtIndexPath: 方法中 -

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSURL *imageURL = [NSURL URLWithString:[arrmImgPaths objectAtIndex:indexPath.row]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];

// [imgvMainView removeFromSuperview];
// Now the image will have been loaded and decoded and is ready to rock for the main thread
dispatch_sync(dispatch_get_main_queue(), ^{

imgvMainView =[[UIImageView alloc] initWithFrame:CGRectMake(34,41,177,124)];
[cell addSubview:imgvMainView];

[imgvMainView setImage:image];
imgvMainView.contentMode = UIViewContentModeScaleAspectFit;

});
});

问题是,当我滚动收藏 View 时,一些图像彼此重叠。请告诉我避免它的解决方案。提前致谢。

最佳答案

请使用下面一行,我希望这能解决我假设的重复单元格问题。

UIImageView* imgvMainView =[[UIImageView alloc] initWithFrame:CGRectMake(34,41,177,124)];[cell.contentView addSubview:imgvMainView];

关于ios:在 Collection View 单元格中重叠图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29846116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com