gpt4 book ai didi

ios - 将图像添加到 UICollectionViewCell 时应用程序崩溃

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

我需要在 UICollectionViewCell 上添加图像和文本。所以我用了这段代码

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

static NSString *cellIdentifier = @"cvCell";
CVCell *cell = (CVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *cellData = [firstSection objectAtIndex:indexPath.row];
[cell.titleLabel setText:cellData];

NSString *imageName = [second objectAtIndex:indexPath.row];

NSLog(@"CV setting image for row %ld from file in bundle with name '%@'", (long)indexPath.row, imageName);

cell.myImageView.image = [UIImage imageNamed:imageName];

return cell;

}

FirstSection 数组有一些名称,Second 数组有图像。显示文本但图像不工作。

所以请告诉我我的代码有什么问题。

我遇到这样的错误:

2014-11-07 15:18:56.928 CollectionViewExample[4459:151457] CV setting image for row 0 from file in bundle with name '(
"real_estate_2.png",
"photography_2.png",
"auto_2.png",
"electronics_2.png",
"services_2.png"
)'
2014-11-07 15:18:56.929 CollectionViewExample[4459:151457] -[__NSArrayI length]: unrecognized selector sent to instance 0x7be86240

2014-11-07 15:18:57.044 CollectionViewExample[4459:151457] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7be86240'
*** First throw call stack:
(
0 CoreFoundation 0x02bf5df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01975a97 objc_exception_throw + 44
2 CoreFoundation 0x02bfda75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x02b469c7 ___forwarding___ + 1047
4 CoreFoundation 0x02b4658e _CF_forwarding_prep_0 + 14
5 UIKit 0x008ad0be +[_UIAssetManager createAssetNamed:fromBundle:] + 66
6

最佳答案

我在UICollectionView中最常犯的错误就是没有写

[self.myCollectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MYCELL"];

您是否尝试过在 imageView 中提供静态图像?如果它有效,那么我认为您的数组中的 UIImage 可能需要类型转换

点击此链接:http://www.techotopia.com/index.php/An_Overview_of_iOS_6_Collection_View_and_Flow_Layout

关于ios - 将图像添加到 UICollectionViewCell 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26796233/

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