您需要使用自定义行和单元格。像这样的东西
class _SearchTextFieldCell<T>: _FieldCell<T> where T: Equatable, T: InputTypeInitiable {
required init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.textField.removeFromSuperview()
let searchTextField = SearchTextField()
searchTextField.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(searchTextField)
self.textField = searchTextField
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class SearchTextCell: _SearchTextFieldCell<String>, CellType {
required public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
open override func setup() {
super.setup()
}
}
class _SearchTextRow: FieldRow<SearchTextCell> {
public required init(tag: String?) {
super.init(tag: tag)
}
}
final class SearchTextRow: _SearchTextRow, RowType {
required public init(tag: String?) {
super.init(tag: tag)
}
}
然后您可以使用自定义行
<<< SearchTextRow() {
$0.title = "Search"
guard let tf = $0.cell.textField as? SearchTextField else {
return
}
tf.filterStrings(["lorem", "ipsum", "dolor", "sit", "amet"])
}