我花了几天时间来解决这个问题,经过多次努力,我在这里问一个问题.我正在使用自定义UITableViewCell,该单元格包含UITextFields.在向表视图添加新单元格时,表格视图表现异常,就像复制单元格一样,当我尝试编辑新单元格的文本字段时,前一个单元格的文本字段也会被编辑.
重复的行为如下:第一个单元格被复制为第三个单元格.我不知道这是由于细胞的可重用性,但有人能告诉我有效的解决方案吗?
我附上了UITableViewCell的截图.
cellForRow的代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : Product_PriceTableViewCell = tableView.dequeueReusableCell(withIdentifier: "product_priceCell") as! Product_PriceTableViewCell
cell.dropDownViewProducts.index = indexPath.row
cell.txtDescription.index = indexPath.row
cell.tfPrice.index = indexPath.row
cell.dropDownQty.index = indexPath.row
cell.tfTotalPrice_Euro.index = indexPath.row
cell.tfTotalPrice_IDR.index = indexPath.row
cell.dropDownViewTotalDiscount.index = indexPath.row
cell.dropDownViewDeposit.index = indexPath.row
cell.tfTotalDeposit_Euro.index = indexPath.row
cell.tfRemaingAfterDeposit_IDR.index = indexPath.row
return cell
}
Run Code Online (Sandbox Code Playgroud)