UITableView Duplicate cells (custom cells with textfields)

Viewed 4404

I have spent days on resolving this issue and after trying much I am asking a question here. I am using a custom UITableViewCell and that cell contains UITextFields. On adding new cells to the table view, the table view behaves abnormal like it duplicates the cell and when I try to edit the textfield of new cell, the textfield of previous cel gets edited too.

The behavior of duplication is as follows: 1st cell is duplicated for 3rd cell. I don't know this is due to reusability of cells but could anyone tell me about the efficient solution?

I am attaching the screenshot of UITableViewCell.

Custom UITableViewCell

The code for cellForRow is as follows:

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
}
2 Answers
Related