Eureka Forms Swift 启用和禁用按钮
Posted
技术标签:
【中文标题】Eureka Forms Swift 启用和禁用按钮【英文标题】:Eureka Forms Swift enable and disable button 【发布时间】:2017-02-15 19:51:51 【问题描述】:我正在使用 Eureka Forms 在我的应用中创建注册函数。
我想弄清楚这个问题。
用户有一些需要给我们的字段。在他关闭所有信息并检查我们想要的所有按钮之前,我希望按钮提交被禁用或隐藏。当所需的行完成时,按钮应该可用/显示。
这是我用尤里卡制作的课程
class RegisterViewController: FormViewController
var xwra = 1
override func viewDidLoad()
super.viewDidLoad()
LabelRow.defaultCellUpdate = cell, row in
cell.contentView.backgroundColor = .red
cell.textLabel?.textColor = .white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 13)
cell.textLabel?.textAlignment = .right
TextRow.defaultCellUpdate = cell, row in
if !row.isValid
cell.titleLabel?.textColor = .red
PhoneRow.defaultCellUpdate = cell, row in
if !row.isValid
cell.titleLabel?.textColor = .red
PickerInlineRow<String>.defaultCellUpdate = cell, row in
if !row.isValid
cell.backgroundColor = .red
PasswordRow.defaultCellUpdate = cell, row in
if !row.isValid
cell.titleLabel?.textColor = .red
ButtonRow.defaultCellUpdate = cell, row in
cell.textLabel?.numberOfLines = 0
form +++ Section("Τα Προσωπικά Στοιχεία σας")
<<< TextRow("name") row in
row.title = "Όνομα"
row.add(rule: RuleRequired())
row.validationOptions = .validatesOnChange
row.placeholder = "Enter text here"
.cellUpdate cell, row in
if !row.isValid
cell.titleLabel?.textColor = .red
<<< TextRow("surname") row in
row.title = "Επώνυμο"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("email") row in
row.title = "Email"
row.add(rule: RuleRequired())
row.add(rule: RuleEmail())
row.placeholder = "Enter text here"
<<< PhoneRow("phone")
$0.title = "Τηλέφωνο"
$0.add(rule: RuleRequired())
$0.placeholder = "Enter text here"
<<< PhoneRow("fax")
$0.title = "Φαξ"
$0.placeholder = "And numbers here"
+++ Section("Η Διεύθυνση σας")
<<< TextRow("company") row in
row.title = "Επωνυμία"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("job") row in
row.title = "Επάγγελμα"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("afm") row in
row.title = "Α.Φ.Μ. / Δ.Ο.Υ"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("address1") row in
row.title = "Διεύθυνση 1"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("address2") row in
row.title = "Διεύθυνση 2"
row.placeholder = "Enter text here"
<<< TextRow("town") row in
row.title = "Πόλη"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< TextRow("tk") row in
row.title = "Τ.Κ."
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
<<< PickerInlineRow<String>("countrytag")
$0.title = "Χώρα"
$0.options = ["Ελλάδα", "Κύπρος"]
$0.add(rule: RuleRequired())
.onChange row in
if row.value == "Ελλάδα"
self.xwra = 1
else
self.xwra = 0
<<< PickerInlineRow<String>("loctag")
$0.title = "Πόλη"
$0.add(rule: RuleRequired())
.onCellSelection( (cell, row) in
if self.xwra == 1
print("its one")
row.options = ["Ελλάδα", "Κύπρος", "Κύπρος", "Κύπρος", "Κύπρος"]
row.updateCell()
else
print("its not one")
row.options = ["Ελλάδα"]
row.updateCell()
)
+++ Section(header: "O Κωδικος σας", footer: "Θα πρέπει να είναι ίδιος και στα δύο πεδία.")
<<< PasswordRow("password")
$0.title = "Password"
<<< PasswordRow()
$0.title = "Confirm Password"
$0.add(rule: RuleEqualsToRow(form: form, tag: "password"))
.cellUpdate cell, row in
if !row.isValid
cell.titleLabel?.textColor = .red
+++ Section("Λήψη Ενημερωτικών Δελτίων")
<<< SwitchRow("SwitchRow") row in
row.title = "The title"
+++ SelectableSection<ImageCheckRow<String>>("", selectionType: .singleSelection(enableDeselection: true))
<<< ImageCheckRow<String>() lrow in
lrow.title = "Έχω διαβάσει και αποδέχομαι τους όρους χρήσης - δήλωσης απορρήτου"
lrow.selectableValue = ""
lrow.value = nil
.cellSetup cell, _ in
cell.trueImage = UIImage(named: "selectedRectangle")!
cell.falseImage = UIImage(named: "unselectedRectangle")!
<<< ButtonRow("terms")
$0.title = "Όροι Χρήσης - Δήλωση Απορρήτου"
$0.presentationMode = .segueName(segueName: "oroi", onDismiss: nil)
<<< ButtonRow("register")
$0.title = "Εγγραφή"
$0.cell.backgroundColor = .red
$0.cell.tintColor = .white
.onCellSelection cell, row in
//send data to server function
有人能告诉我如何让它工作吗? 非常感谢!
更新 1。
最后一个按钮
<<< ButtonRow("register")
$0.title = "Εγγραφή"
$0.cell.backgroundColor = .red
$0.cell.tintColor = .white
.onCellSelection cell, row in
row.section?.form?.validate()
在选择单元格时,检查所有需要的数据,如果它们不正确,则文本变为红色。 所以问题又是一样的。如果验证为真,我如何运行发送到服务器功能?
【问题讨论】:
【参考方案1】:我遇到了同样的问题,下面的代码获取错误计数,如果它是 0 表格是好的,如果它有任何错误它什么都不做,则继续你的下一个函数。
<<< ButtonRow() (row: ButtonRow) -> Void in
row.title = "LOGIN"
.onCellSelection [weak self] (cell, row) in
print("validating errors: \(row.section?.form?.validate().count)")
if row.section?.form?.validate().count == 0
self?.loginAction(row)
【讨论】:
此答案应标记为正确。它实际上解决了问题。谢谢那个人【参考方案2】:此示例在末尾添加一个按钮,该按钮将被禁用,直到所有行都通过验证:
<<< ButtonRow("signin")
$0.title = "Sign In"
$0.disabled = Condition.function(
form.allRows.flatMap $0.tag , // All row tags
!$0.validate().isEmpty ) // Form has no validation errors
【讨论】:
以上是关于Eureka Forms Swift 启用和禁用按钮的主要内容,如果未能解决你的问题,请参考以下文章
Swift Eureka forms:如何限制多值部分中的行数?
Swift 3 Eureka Forms 更改按钮行字体颜色