我有一个自定义布局的集合视图。它包含用户可以更新的文本字段,并将保存到数组中。文本字段占据了整个集合视图单元格,基本上它看起来像 Microsoft Excel 等,并且可以水平和垂直滚动。
问题是,如果您在文本字段中输入数字并滚动集合视图而不按回车键,则单元格出列并且索引路径变为空。
如果滚动集合视图,我希望文本字段结束编辑。
这是我用于 textFieldDidEndEditing 的代码。
- (void)textFieldDidEndEditing:(UITextField *)textField {
UICollectionViewCell *selectedCell = (UICollectionViewCell *)[[textField superview] superview];
UICollectionView *collectionViewForSelection = (UICollectionView *)[selectedCell superview];
NSIndexPath *textFieldIndexPath = [collectionViewForSelection indexPathForCell:selectedCell];
if (textFieldIndexPath != NULL) {
[[_collectionArray objectAtIndex:textFieldIndexPath.section] replaceObjectAtIndex:textFieldIndexPath.row withObject:textField.text];
[self saveArray];
}
}
我尝试过没有任何运气,也没有发布任何尝试中的代码。
关于如何做到这一点的任何建议?