gpt4 book ai didi

ios - 自定义CollectionView使iOS崩溃

转载 作者:行者123 更新时间:2023-12-01 18:17:59 26 4
gpt4 key购买 nike

我已经实现了Custom CollectionView,但是当我运行我的应用时,它崩溃并显示,
错误:[UICollectionViewCell Mylabel]:无法识别的选择器已发送到实例...

这是我的代码段,

- (void)viewDidLoad {

[super viewDidLoad];

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];
}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { // No of Rows..

CGSize result = [[UIScreen mainScreen] bounds].size;

if(result.height == 480) //3.5"
{
return 3;
}
else // 4"
{
return 4;
}
}

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { // No of Columns..
return 2;
}

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

CollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cvCell" forIndexPath:indexPath];

if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CollectionViewCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CollectionViewCell class]])
cell = (CollectionViewCell *)oneObject;
}

cell.Mylabel.text=@"I am label";
cell.backgroundColor= [UIColor yellowColor];

return cell;
}

我在哪里做错了?请事先帮助和thanx

最佳答案

我不确定您的问题,但我遇到了类似的问题。

我从代表中删除了这一行:

if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CollectionViewCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CollectionViewCell class]])
cell = (CollectionViewCell *)oneObject;
}

我在“查看并加载”中添加了此代码
UINib *cellNib = [UINib nibWithNibName:@"CollectionViewCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cellID"];

也许这可以帮助您

关于ios - 自定义CollectionView使iOS崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19810753/

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