使用 a UICollectionView
,我正在尝试添加另一个UICollectionViewCell
. 第一个代码显示了第一个 Cell,它运行良好。当我尝试添加另一个UICollectionViewCell
.
static NSString *identifier = @"Cell"; // Default Cells
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *illustrationImage = (UIImageView *)[cell viewWithTag:100];
illustrationImage.image = [UIImage imageNamed:[stackImage objectAtIndex:indexPath.row]];
UILabel *stackLabel = (UILabel *)[cell viewWithTag:12];
[stackLabel setText:[stackTitle objectAtIndex:indexPath.row]];
在这里,我想在我的UICollectionView
. 每当我运行这段代码时,整个事情都拒绝启动:
static NSString *newIdentifier = @"AddNewCell";
UICollectionViewCell *newCell = [collectionView dequeueReusableCellWithReuseIdentifier:newIdentifier forIndexPath:indexPath];
UIImageView *addNewImage = (UIImageView *)[newCell viewWithTag:120];
addNewImage.image = [UIImage imageNamed:[addNew objectAtIndex:indexPath.row]]; // This line makes the app crash
return cell;
return newCell;
错误信息
由于未捕获的异常“NSRangeException”而终止应用程序,原因:“ * -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]”
我怀疑这与indexPath.row
. 如果我将indexPath.row
以下代码中的部分替换为“0”,则它不会崩溃,但它不会在以下代码中可见UICollectionView
:
[addNew objectAtIndex:indexPath.row]]