gpt4 book ai didi

ios - collectionview 自定义单元格没有出现

转载 作者:行者123 更新时间:2023-11-29 10:24:49 26 4
gpt4 key购买 nike

我使用自定义单元格创建 collectionview 并且它工作正常,但是当我在应用程序中更新时它不起作用,我不知道为什么。

[self.collectionView registerClass:[CellItem class] forCellWithReuseIdentifier:@"CellItem"];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CellItem* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellItem"
forIndexPath:indexPath];
//cell.backgroundColor = [UIColor redColor];
NSDictionary* celldata = [productsDictionary objectAtIndex:indexPath.row];
NSString* productName = [celldata objectForKey:@"name"];
NSString* productImage = [celldata objectForKey:@"image"];

dispatch_async(dispatch_get_global_queue(0,0), ^{

NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: productImage]];
if (data == nil)
return;
dispatch_async(dispatch_get_main_queue(), ^{

// WARNING: is the cell still using the same data by this point??

cell.imageViewProduct.image = [UIImage imageWithData: data];

//cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData: data]];
});
});
[cell.lableTitle setText:productName];
return cell;
}

对于 itemcell 类:

@property (weak, nonatomic) IBOutlet UITextView *lableTitle;

@property (weak, nonatomic) IBOutlet UIImageView *imageViewProduct;

这里的输出图像: http://i.stack.imgur.com/bcZaw.jpg

最佳答案

请尝试删除

[self.collectionView registerClass:[CellItem class] forCellWithReuseIdentifier:@"CellItem"];

您使用的是自定义 UICollectionViewCell,因此您不应使用 registerClass

关于ios - collectionview 自定义单元格没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32884372/

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