用户清除DateTimeRow Eureka表单的方式

问题描述 投票:0回答:1

我正在将Eureka用于我的iOS表单。我有几个Datetime行最初是空白的,但是一旦用户点击该字段,当前的Date()就会自动填充到该字段中。请参阅此帖子底部的图片。

这里的问题是,我需要一种很好的方式让用户清除时间,并且在用户输入日期后将该字段恢复为零。

我当时在想键盘附件视图中的“清除”按钮,但我想不出一种用尤里卡做的方法。

也欢迎其他任何实现建议!

这是DateTimeRow的代码

<<< DateTimeRow("Tag Name"){ row in
  row.disabled = Condition(booleanLiteral: self.dataEdit?.isLocked ?? false)
} .cellSetup { (cell, row) in
  row.title = "Duty Start Time"
  row.value = self.dataEdit == nil ? nil : self.dataEdit?.dutyStart
  row.dateFormatter?.timeZone = TimeZone(secondsFromGMT: 0)
  cell.datePicker.timeZone = TimeZone(secondsFromGMT: 0)
} .onChange{ row in
  //currently empty
} .onCellHighlightChanged({ (cell, row) in
  // this used to fill in the current date once the user taps on an empty field
  if row.value == nil {
    row.value = Date()
  }
})

enter image description here

ios swift xcode eureka-forms
1个回答
2
投票

您可以修改附件视图。首先添加该类。

class CamelAccessoryView : NavigationAccessoryView {

        override init(frame: CGRect) {
            super.init(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: 44.0))
            autoresizingMask = .flexibleWidth
            fixedSpace.width = 22.0
            setItems([previousButton, fixedSpace, nextButton, flexibleSpace, clearButton, fixedSpace, doneButton], animated: false)
        }

        var clearButton = UIBarButtonItem(title: "Clear", style: UIBarButtonItem.Style.plain, target: nil, action: nil)
        var fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        var flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }

    }

在您的控制器中,优先级例如

class RowsExampleViewController: FormViewController {

    override var customNavigationAccessoryView: (UIView & NavigationAccessory)? {
        // The width might not be correctly defined yet: (Normally you can use UIScreen.main.bounds)
        let navView = CamelAccessoryView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 44.0))
        navView.previousButton.target = self
        navView.clearButton.target = self
        navView.clearButton.action = "clearAction:"
        return navView
    }

它将添加一个清除按钮。将会警告您“没有用Objective-C选择器'clearAction:'声明的方法。

进行选择以清除输入。

当单击该功能时,得到您的输入,例如

let yourInput = self.form.rowBy(tag: "Tag Name") as! DateTimeRow
yourInput.value = "" // just clear it 

更新:::

尝试这样更改您的功能。

@objc func clearAction(button: UIBarButtonItem){
    guard let currentRow = tableView?.findFirstResponder()?.formCell()?.baseRow else { return }
    currentRow.baseValue = nil
    currentRow.updateCell()
}

如果不行,请尝试使用第二个选项来创建全局tagNo变量以获取已选择的行。

© www.soinside.com 2019 - 2024. All rights reserved.