我使用自定义单元格创建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
答案 0 :(得分:1)
请尝试删除
[self.collectionView registerClass:[CellItem class] forCellWithReuseIdentifier:@"CellItem"];
您使用自定义UICollectionViewCell,因此不应使用registerClass
答案 1 :(得分:0)
答案 2 :(得分:0)
尝试使用寄存器nib函数而不是寄存器类。
[collectionView registerNib:[UINib nibWithNibName:@"你的手机笔尖名称" bundle:nil] forCellWithReuseIdentifier:@"你的小区标识符"];
让我知道它是否适合你。