表格视图单元格数据滑动iOS Swift 4时清除

问题描述 投票:-1回答:1

我在表视图中设置了不同的单元格。我在表格视图单元格中使用textfield和dropdown。问题是,当我在下拉列表中选择值并在Textfield中写入一些文本并向上滑动然后向上滑动到顶部时,我在Textfield中写入的数据为空,我的下拉列表显示用于填充数据的那些值​​,而不是选中的值。我如何将数据保存为丢失。如果我想要,如果我从上到下,从下到上滑动,我的数据显示为我输入。如何准确地执行此任务。谢谢。屏幕截图附加。 enter image description here

enter image description here

这是我的代码,

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let objData = dataArray[indexPath.row]

    if objData.fieldType == "textfield"  && objData.hasPageNumber == "1" {
        let cell: AdPostCell = tableView.dequeueReusableCell(withIdentifier: "AdPostCell", for: indexPath) as! AdPostCell

        if let title = objData.title  {
            cell.txtType.placeholder = title
        }

        if let fieldValue = objData.fieldVal {
            cell.txtType.text = fieldValue
        }
        cell.fieldName = objData.fieldTypeName

        return cell
    }

    else if objData.fieldType == "select" && objData.hasPageNumber == "1"  {
        let cell: AdPostPopupCell = tableView.dequeueReusableCell(withIdentifier: "AdPostPopupCell", for: indexPath) as! AdPostPopupCell

        if let title = objData.title {
            cell.lblType.text = title
        }

        if let fieldValue = objData.fieldVal {
            cell.oltPopup.setTitle(fieldValue, for: .normal)
        }
        var i = 1
        for item in objData.values {
            if item.id == "" {
                continue
            }
            if i == 1 {
                cell.oltPopup.setTitle(item.name, for: .normal)
                cell.selectedKey = String(item.id)
            }
            i = i + 1
        }
        cell.btnPopUpAction = { () in
            cell.dropDownKeysArray = []
            cell.dropDownValuesArray = []
            cell.hasCatTemplateArray = []
            cell.hasTempelateArray = []
            cell.hasSubArray = []
            for items in objData.values {
                if items.id == "" {
                    continue
                }
                cell.dropDownKeysArray.append(String(items.id))
                cell.dropDownValuesArray.append(items.name)
                cell.hasCatTemplateArray.append(objData.hasCatTemplate)
                cell.hasTempelateArray.append(items.hasTemplate)
                cell.hasSubArray.append(items.hasSub)
            }
            cell.popupShow()
            cell.selectionDropdown.show()
        }
        cell.fieldName = objData.fieldTypeName
        return cell
    }
    return UITableViewCell()
}
swift xcode tableview
1个回答
0
投票

这是dequeueReusableCell的一个问题,它重复使用细胞以避免内存浪费。当更改并在cellForRowAt中的单元格中更新时,您可以使用数组来保存每个单元格的数据。

© www.soinside.com 2019 - 2024. All rights reserved.