![](/img/trans.png)
[英]When calling -reloadData, -collectionView:didSelectItemAtIndexPath: not called
[英]Calling UICollectionView#reloadData in UICollectionViewDelegate#collectionView:didSelectItemAtIndexPath: hides all cells
我有一个UIViewController,它对didSelectItemAtIndexPath具有以下实现
@interface
id section1Item
NSMutableArray *section2Items
NSMutableArray *section3Items
@end
@implementation
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
;
} else if (indexPath.section == 1) {
self.section1Item = [self.section2Items objectAtIndex:indexPath.row];
} else { // indexPath.section == 2
id newSection2Item = [self.section3Items objectAtIndex:indexPath.row];
[self.section2Items addObject:newSection2Item];
[self.section3Items removeObject:newSection2Item];
}
[collectionView reloadData];
}
@end
代码背后的想法是,我的collectionView具有静态的节数,点击第3节中的项目会将项目移至第2节,而点击第2节中的项目将使其成为第1节中的项目。
但是,一旦我对dataStructure(section1Item,section2Items和section3Items)进行了更改并调用reloadData,我的所有UICollectionView单元都会消失。 问题的一些症状
工具详细信息:我正在iOS7模拟器上使用XCode5-DP6。
更新:我的UICollectionView在第一次渲染时正确显示了所有单元格。
好的,偷看,所以我能够找出问题所在。 委托(自己)是UIViewController
的子类。 在初始化中,我分配了self.view = viewFromStoryBoard
,其中viewFromStoryBoard由调用者传递,并在情节self.view = viewFromStoryBoard
中进行设置。
由于我实际上并没有使用子类UIViewController
提供的任何功能,因此我决定切换到子类NSObject
并手动保留指向UICollectionView
的指针。
这解决了我的问题。 但是,我对问题的确切性质不是100%的。 我猜测以某种方式覆盖UIViewController的视图并不是它看起来的全部。
iOS 7和UICollectionView有很多错误...就我而言,reloadData无法正常工作,它会延迟工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.