【发布时间】:2015-01-18 06:52:05
【问题描述】:
我已经使用集合视图创建了一个 excel 视图。早些时候,我在滚动列出的集合视图时遇到了一个问题: https://stackoverflow.com/questions/27036224/scrolling-disturbs-layout-of-collectionview 在看到 Shivam 的回复后,我解决了这个问题: Collection View,with custom layouts, cells misbehave on scrolling
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellID = [NSString stringWithFormat:@"%@%d", @"cCell",indexPath.row];
[myCollectionView registerClass: [CustomCell class] forCellWithReuseIdentifier:cellID];
CustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
[self configureCell:cell forIndexPath:indexPath];
return cell;
}
-(void)configureCell:(CustomCell*)cell forIndexPath:(NSIndexPath*)indexPath{
// configuration code
}
我不知道它是否正确,但它的工作原理。但现在我陷入了与重新加载集合视图相关的另一个问题。
Problem::: 我在已实现 textFieldDidEndEditing 委托的单元格中有文本字段。我还提供了 Next Button,它根据我的需要为集合视图中的所有单元格提供代理导航。在下一个按钮的单击方法中,我正在保存 currentIndexpath,重新加载集合视图,使用保存的索引路径获取下一个单元格,获取文本字段并将其作为第一响应者。但是下一个文本字段永远不会成为第一响应者。我调试了这个问题,发现重新加载后我无法检索单元格。如果我删除重新加载线,那么一切正常。
NSIndexPath *reqIndexPath = [NSIndexPath indexPathForItem:colId inSection:currentSection];
CustomCell *cell = (CustomCell*)[self.collectionView cellForItemAtIndexPath:reqIndexPath];
【问题讨论】:
-
我在stackoverflow.com/questions/18230918/…看到Lukewar的解决方案后解决了这个问题刚刚添加了[self.collectionView layoutIfNeeded];重载数据后
标签: ios reload collectionview