【问题标题】:unable to get cell after uicollectioniew reloaduicollectionview 重新加载后无法获取单元格
【发布时间】: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];

【问题讨论】:

标签: ios reload collectionview


【解决方案1】:

我通过以下方式解决了这个问题:

   [self.collectionView reloadData];
   [self.collectionView layoutIfNeeded];

感谢 Lukewar 的回复 Reloading a UICollectionView using reloadData method returns immediately before reloading data

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    相关资源
    最近更新 更多