Я использую Eureka Forms для регистрации функций в своем приложении.Кнопка включения и выключения Eureka Forms Swift
И я хотел бы выяснить эту проблему.
У пользователя есть поля, необходимые для предоставления нам. Пока он не оставляет прав на всю информацию, и он проверяет все кнопки, которые мы хотим, я бы хотел, чтобы кнопка представлялась отключенной или скрытой. И когда строки, которые требуются, завершены, тогда кнопка должна быть доступна/показана.
Это класс, который я сделал с эврика
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
}
}
}
Может кто-то момент мне о том, как заставить его работать? Спасибо большое!
Update 1.
Последняя кнопка
<<< ButtonRow("register") {
$0.title = "Εγγραφή"
$0.cell.backgroundColor = .red
$0.cell.tintColor = .white
}
.onCellSelection { cell, row in
row.section?.form?.validate()
}
При выборе ячейки, проверьте все данные, которые необходимы, и если они не исправны текст становится красным. Итак, вопрос опять тот же. Как запустить функцию отправки на сервер в случае, если проверка правильна?
Этот ответ должен быть отмечен как правильный. Это фактически решает проблему. Спасибо за этого человека –