gpt4 book ai didi

ios - UICollectionViewCell setAsset 无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 03:22:37 26 4
gpt4 key购买 nike

我正在尝试创建一个照片库。我的 cellForItemAtIndexPath 代码如下。

  - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PhotoCell *cell = (PhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath];
ALAsset *asset = self.assets[indexPath.row];
cell.asset = asset; // crash on this line
cell.backgroundColor = [UIColor redColor];
return cell;
}

应用程序在 cell.asset = asset; 行崩溃并给出错误:-[UICollectionViewCell setAsset:]: unrecognized selector sent to instance 0xa226fd0

PhotoCell.h 是这样的:

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>

@interface PhotoCell : UICollectionViewCell
@property(nonatomic, strong) ALAsset *asset;

@end

PhotoCell.m 是:

#import "PhotoCell.h"

@interface PhotoCell ()
@property(nonatomic, weak) IBOutlet UIImageView *photoImageView;
@end

@implementation PhotoCell
- (void)setAsset:(ALAsset *)asset
{
_asset = asset;
self.photoImageView.image = [UIImage imageWithCGImage:[asset thumbnail]];
}

@end

我找不到应用程序崩溃的任何原因。我在哪里犯错?与 Storyboard 内容有关吗?

最佳答案

你应该用你的 UICollectionView 注册你的单元格类

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

关于ios - UICollectionViewCell setAsset 无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897794/

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