大佬教程收集整理的这篇文章主要介绍了ios – 在超出边界范围内调用cellForItemAtIndexPath,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用相当短的照片列表创建新视图/集合视图时会出现问题 – 通常小于30.当我旋转设备时,集合视图会尝试重新渲染,并且应用程序崩溃时出现“索引X超出bounds [0 .. Y]“,其中x是大于Y的数字(数组的最后一个元素).
我注意到,只有当新显示的集合视图的项目少于“根”集合视图时,才会发生这种情况.
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { return [[photos objectForKey:api.directoryID] count]; } - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { return 1; } - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemATindexPath:(NSIndexPath *)indexPath { PhotoCell *photoCell = [cv dequeueReusableCellWithReusEIDentifier:@"Cell" forIndexPath:indexPath]; photoCell.photo = [[photos objectForKey:api.directoryID] objectATindex:indexPath.row]; return photoCell; }
至少,我想对cellForItemATindexPath进行try / catch,但不知道我将把try / catch放在哪里.也许在自定义UICollectionView中?
谢谢!
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { return [[photos objectForKey:api.directoryID] count]; }
我假设您为所有UICollectionView实例使用一个委托和datasource对象.
如果是这样,请以这种方式重写代码:
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { if ( view == _firstCollectionView ) { return [[photos objectForKey:api.directoryID] count]; } else if ( view == _secondCollectionView ) { return ...; } }
以上是大佬教程为你收集整理的ios – 在超出边界范围内调用cellForItemAtIndexPath全部内容,希望文章能够帮你解决ios – 在超出边界范围内调用cellForItemAtIndexPath所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。