gpt4 book ai didi

ios - 如何创建自定义 TextCell 和 TextRow,其中包含 UITextField 的子类?

转载 作者:行者123 更新时间:2023-11-28 11:52:54 25 4
gpt4 key购买 nike

我正在使用 Eureka FormsSearchTextField .

在我的表单中,我想要一些与 (Eureka) 内置的非常相似的东西 TextRow .不同的是这个自定义TextRow将使用 SearchTextField而不是常规的 UITextField .

我首先想到我可以复制与TextRow相关的所有代码和 TextCell并稍微重命名类。但是,我在 _FieldRow 中找到了代码很难理解,我不知道应该复制哪些代码。

然后我看到我可以设置 cellProvider提供自定义单元格的属性:

<<< TextRow() {
$0.cellProvider = CellProvider<TextCell>(nibName: "NewCustomCell", bundle: .main)
$0.title = "TextRow"
}

所以我想我只需要一个 xib 文件。我试图找到 Eureka 用于其 TextCell 的 xib 文件这样我就可以复制它并稍微编辑它但是我在 Pods/Eureka 下找不到一个 xib 文件目录。然后我尝试制作自己的 xib 文件。

添加表格 View 单元格后,我将其类设置为 TextCell因为我需要一个CellProvider<TextCell> .然后我尝试将文本字段和标签连接到 IBOutlet_FieldCell (这就是我应该做的,对吧?)但网点就是不出现。我把类(class)改为_FieldCell他们正确地出现了,但我不能通过带有 _FieldCell 的 Nib 进入CellProvider<TextCell> ,我可以吗?

重申我的目标:创建一个具有 SearchTextField 的表单单元格作为文本字段,其行为与 TextCell 相同对于其他一切。

最佳答案

您需要使用自定义行和单元格......像这样

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"])
}

关于ios - 如何创建自定义 TextCell 和 TextRow,其中包含 UITextField 的子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com