尝试将节标题添加到我的 uicollectionview。当我不使用节标题时,集合视图加载正常,完全没有问题。当我尝试使用一个时,我收到此错误:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
我看到其他人有这个问题,但还没有找到解决办法。我在情节提要中创建了 uicollectionview、单元格和剖面视图。我正在注册头类并在代码中设置数据源和委托。
同样,uicollectionview 可以 100% 正常工作,而无需尝试使用节标题。似乎有一个节标题会导致应用程序尝试自动调用数据源/委托方法,而不是等待我的编程调用。为什么是这样?
代码:
[self.collectionView registerClass:[MyCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyCollectionHeaderView"];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;