简体   繁体   English

一种用户清除 DateTimeRow Eureka Forms 的方法

[英]A way for user to clear DateTimeRow Eureka Forms

I am using Eureka for my iOS forms.我正在为我的 iOS forms 使用 Eureka。 I've got several Datetime rows are initially blank, but once the user taps on the field, the current Date() is filled into the field automatically.我有几个 Datetime 行最初是空白的,但是一旦用户点击该字段,当前 Date() 就会自动填充到该字段中。 See image at the bottom of this post.请参阅这篇文章底部的图片。

The problem here is i need a good way for the user to clear the time, and for the field to revert back to nil after the user has already entered a date.这里的问题是我需要一个好方法让用户清除时间,并在用户输入日期后让字段恢复为零。

I was thinking a "clear" button in the keyboard accessory view, but i cant figure out a way to do it with eureka.我正在考虑键盘附件视图中的“清除”按钮,但我无法找到使用尤里卡的方法。

Any other implementation suggestions welcomed too!也欢迎任何其他实施建议!

Here's the code i have for the DateTimeRow这是我为 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()
  }
})

在此处输入图像描述

you can modify accessoryview.您可以修改附件视图。 first add that class.首先添加 class。

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

    }

in your controller override is such as在你的 controller 覆盖是这样的

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
    }

it will add a clear button.它将添加一个清除按钮。 there will be warning for you "No method declared with Objective-C selector 'clearAction:'.将向您发出警告“没有使用 Objective-C 选择器‘clearAction:’声明的方法。

make a selector to clear your input.制作一个选择器来清除您的输入。

when clicked the function get your input such as当点击 function 获取您的输入,例如

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

update:::更新:::

try to change your func like that.尝试像那样改变你的功能。

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

if this not works try second option for making a global tagNo variable to get which row has been selected.如果这不起作用,请尝试第二个选项来制作全局 tagNo 变量以获取已选择的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM