如果 an 中的模型数据NSArray没有改变,并且您调用reloadData,UICollectionView单元格是否出现在不同的位置?
我发现如果我NSArray持有 Obj1、Obj2、Obj3,那么首先,UICollectionView正确地将 Obj1 映射到第一个collectionViewCell,Obj2 到第二个等等。这就是它在 中的设置方式cellForRowAtIndexPath,因为它用于indexPath.row获取正确的 Obj从数组。
但是,当我调用时reloadData,所有对象都映射到错误的 UICollectionViewCell (Obj1 最终出现在其他地方,例如第二个collectionViewCell,而 Obj2 最终成为第三个collectionViewCell等)
为什么会这样?我没有在文档中找到原因。
此外,当我的模型数组发生变化时,我遇到了同样的问题。例如,如果我NSArray的是 Obj1、Obj2、Obj3,然后创建了新的 Objs 实例并且现在以不同的顺序,例如NSArrayis Obj2、Obj3、Obj1... 然后我调用reloadData,我面临同样的情况问题。
Obj2 没有UICollectionViewCell按应有的方式映射到第一个,而是映射到不同的UICollectionViewCell
任何人都知道为什么会发生这种情况UICollectionViews?
谢谢!
编辑:代码cellForRowAtIndexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MIAppCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"MIAppCell" forIndexPath:indexPath];
// set model data
[cell setAppTitle:[(MIAppDO*)[self.apps objectAtIndex:indexPath.row] getAppTitle]];
return cell;
}