将UI添加到单元格快速

时间:2019-05-19 10:44:46

标签: swift

我有一个使用动态UI的应用程序,并且我是Apple来确定要添加到单元格的UI类型的条件。现在的问题是,当添加UI时,它是不可编辑的,例如,如果添加了uitextfield,我将无法添加任何输入或对其进行编辑,并且如果添加了日期选择器,则无法对其进行编辑。欢迎任何帮助。下面是我的代码的附件

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellModel = elements[indexPath.row]
        let cellIdentifier = cellModel.unique_id
//            cellModel.type.rawValue
        let customCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier!, for: indexPath) as! CustomElementCell

        customCell.configure(withModel: cellModel)

        return customCell as! UITableViewCell
    }

//我的手机

func configureUI(type: String, placeholder: String) {

        let type = TypeView.typeCell(type: type, placeholder: placeholder)
        switch type {

        case .text:
            let tf = DefaultTextField()
            tf.placeholder = placeholder
            self.contentView.addSubview(tf)
            log("THE LOG test")
        case .embeddedphoto:
            let tf = DefaultTextField()
            tf.placeholder = placeholder
            tf.keyboardType = .numberPad
            log("THE LOG embeddedphoto")
        case .formattednumeric:
            let tf = DefaultTextField()
            tf.placeholder = placeholder
            log("THE LOG formattednumeric")
        case .datetime:
            let dp = UIDatePicker()
            self.contentView.addSubview(dp)
            log("THE LOG datetime")
        }

    }

1 个答案:

答案 0 :(得分:0)

1-您应为每种动态类型创建一个单元格并进行注册

2-对于当前的实现,您需要向添加的元素添加约束并清除单元格以避免出队问题