【发布时间】:2018-04-20 04:34:40
【问题描述】:
我正在尝试在collectionView 中显示图像。从服务器获取 17 张图像的数据。我拿了一个名为Imageofarray 的Array。我将 17 张图片附加到 array。当我要在collectionView 中显示时,它显示以下异常:
发送到实例的无法识别的选择器
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ProudpartnersViewCell *myCell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"cell"
forIndexPath:indexPath];
myCell.layer.masksToBounds = NO;
myCell.layer.shadowRadius = 5;
myCell.layer.shadowOffset = CGSizeMake(0.0, 3.0);
myCell.layer.shadowOpacity = 0.2
NSString *strImg_Path = [[NSString alloc]init];
NSString *arrayResult = [imageOfArray objectAtIndex:indexPath.row]; // error is here
strImg_Path = [NSString stringWithFormat:@"%@",[NSURL URLWithString:arrayResult]];
[myCell.proudOfImages sd_setImageWithURL:[NSURL URLWithString:strImg_Path]
placeholderImage:[UIImage imageNamed:@"placeholer_image"]];
return myCell;
}
谢谢你
【问题讨论】:
-
显示你的数组。
-
您的应用因“类型转换”问题而崩溃。检查 [imageOfArray objectAtIndex:indexPath.row] 的类型。它在数组索引中是哪种类型的对象。
-
你能检查一下我的数组吗( 17, {onsorImage = "13.126.20.47/app/cykulpelotons/sponsors/images/pega.jpg"; }, {onsorImage = "13.126.20.47/app/cykulpelotons/sponsors/images/yogabar.jpg"; }, {onsorImage = "13.126.20.47/app/cykulpelotons/sponsors/images/cykul.png"; }, {赞助商图片 = "13.126.20.47/app/cykulpelotons/sponsors/images/tsiic.png"; },
-
您的数组的第一个索引对象是一个整数 (17),您正在尝试将类型转换为字符串。
-
你看到了吗,你的第0个索引是数字
17,在刷新数据之前删除这个并使用
标签: ios objective-c arrays uicollectionview