我的视图有一个表视图,每行都有一个集合视图。集合单元格有一个文本字段(及其子类)、一个标签和一个文本视图,它们都是全尺寸的,并且除了一个之外的所有单元格都根据单元格位置隐藏。
当编辑其中一个文本字段时,委托 (CollectionView) 将新值传递回视图控制器以更改数组,然后重新加载适当的单元格,因为其中有计算数据。
问题是第二次编辑其中一个文本字段时,两个单元格交换宽度,如果您再编辑文本字段两次,似乎会交换回来,但边框仍处于错误的位置。
初始加载后的表:

两次改变数量后的表格

文本字段和视图委托方法
func textFieldDidEndEditing(_ textField: UITextField) {
let currencyField = textField as! CurrencyField
let indexPath = indexPathForCellWithSubview(cellSubview: textField)!
(dataSource as! DetailViewController).changeData(tableRow: tag, collectionItem: indexPath.row, newData: currencyField.decimal)
let indexPaths: [IndexPath] = [IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 4, section: 0),IndexPath(row: 5, section: 0)]
collectionViewLayout.invalidateLayout()
reloadItems(at: indexPaths)
}
func textViewDidEndEditing(_ textView: UITextView) {
let indexPath = indexPathForCellWithSubview(cellSubview: textView)!
let indexPaths: [IndexPath] = [IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 4, section: 0),IndexPath(row: 5, section: 0)] …Run Code Online (Sandbox Code Playgroud)