Swift Eureka:向 ButtonRow 添加文本值

1 ios cocoapods swift eureka-forms

目前,我通过向单元格添加标签视图来使用 ButtonRow 获得此结果:

在此输入图像描述

<<< ButtonRow("Email") {
            $0.title = $0.tag
            $0.presentationMode = PresentationMode.Show(...)
            }.cellSetup {
                cell, row in

                let text = UILabel(frame: cell.frame)
                text.frame.size.width = 0.909 * currentScreenWidth - 68
                text.frame.origin.x = 68
                text.textColor = UIColor(red: 142/255, green: 142/255, blue: 147/255, alpha: 1)
                text.textAlignment = .Right
                text.text = "fakeEmail@email.com"
                cell.addSubview(text)
 }
Run Code Online (Sandbox Code Playgroud)

我使用 ButtonRow 是因为它末尾有一个小“>”,并且在以编程方式呈现新视图和视图控制器时效果很好。

使用$0.value = "Some String"不起作用,就像使用其他属性一样。

有没有办法做到这一点而无需手动添加标签视图?它适用于所有屏幕,但尽管如此,我认为手动设置这些参数并不是很安全。

小智 6

ButtonRow 的实现在初始化单元格对象时使用 UITableViewCellStyle 'default'。您可以创建 ButtonRow 的子类:

public final class DetailedButtonRowOf<T: Equatable> : _ButtonRowOf<T>, RowType {
    public required init(tag: String?) {
        super.init(tag: tag)
        cellStyle = .value1
    }
}
public typealias DetailedButtonRow = DetailedButtonRowOf<String>
Run Code Online (Sandbox Code Playgroud)

然后您可以指定该行的detailLabelText:

<<< DetailedButtonRow("Email") { row in
    row.title = row.tag
    row.presentationMode = .segueName(segueName: "AStoryboardSegue", onDismiss: nil)
}.cellUpdate({ (cell, row) in
    cell.detailTextLabel?.text = "fakeEmail@email.com"
})
Run Code Online (Sandbox Code Playgroud)