swift - 将 UI 快速添加到单元格
问题描述
我有一个应用程序,我正在使用动态 UI,我很乐意调整要添加到单元格的 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-您应该为每个动态类型创建一个单元格并注册它
2-对于您当前的实现,您需要为添加的元素添加约束并清除单元格以避免出队问题
推荐阅读
- html - 如何将下拉列表和文本框放在一行中?
- sql - Powershell 和 Regex 来整理生成的 SQL 脚本
- php - Laravel 捕获 Artisan:调用异常
- google-sheets - Google 表格:Arrayforumla 作为 sumif 中的 sum_range 参数引发错误
- html - 如何给画布最大空间并在其上放置左侧(可滚动)和右侧“菜单”div?
- java - Selenium 抛出 StaleElementReferenceException
- php - INSERT 中的子查询在 PDO 中的执行方式与 SQL 不同
- ios - 使用 IIS 重写替换 URL 中的 %5E
- javascript - 如何在reactjs中以fullcalendar传递数据并在handleDateClick中检索
- javascript - 检查密码匹配,意外操作。怎么了?