ios 不关闭重新加载集合的键盘ViewCell

4nkexdtk  于 8个月前  发布在  iOS
关注(0)|答案(3)|浏览(56)

我有一个UICollectionView,里面有一个UITextView的自定义单元格。用户可以点击文本字段内的任何文本。当文本字段的高度大于单元格的大小时,单元格会建议集合视图重新加载自己。

-(void)updatedCell:(UICollectionViewCell*)cellToUp{

    NSIndexPath *indexPath = [self.collectionView indexPathForCell:cellToUpdateSize];

    BOOL animationsEnabled = [UIView areAnimationsEnabled];
    [UIView setAnimationsEnabled:NO];
    [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
    [UIView setAnimationsEnabled:animationsEnabled];

}

字符串
问题是,当单元格正在“重新加载”时,键盘被关闭,并重新显示,没有任何文本字段与之关联。有什么解决方案可以避免关闭键盘吗?
先谢了。

edqdpe6u

edqdpe6u1#

您可以覆盖UICollectionView上的reload函数。
比如说:

[super reloadData];
[textView becomeFirstResponder];

字符串

lx0bsm1f

lx0bsm1f2#

这样做:

collectionView.collectionViewLayout.invalidateLayout()

字符串

abithluo

abithluo3#

你好,你可以使用UICollectionView方法performBatchUpdates(_:completion:)来修改相关单元格的高度,而无需重新加载单元格。代码如下

[self.collectionView performBatchUpdates:^{
    UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:currentRow inSection:currentSection]];
    if (cell) {
        cell.height = [[self.colHeightArray objectAtIndex:currentRow] floatValue];
    }
} completion:^(BOOL finished) {
}];

字符串
希望这对你有帮助。

相关问题