Ios 从Swift中的Eureka表单获取值
我是Swift的新编程人员,我正在尝试使用Eureka库创建表单 表单已在运行,但我无法从表单中获取数据 我试图一个接一个地获取数据,并将其存储到一个全局变量中,以便在按下按钮时打印 问题是代码总是出错,我不知道如何更正它 这是我的代码:Ios 从Swift中的Eureka表单获取值,ios,swift,swift3,eureka-forms,Ios,Swift,Swift3,Eureka Forms,我是Swift的新编程人员,我正在尝试使用Eureka库创建表单 表单已在运行,但我无法从表单中获取数据 我试图一个接一个地获取数据,并将其存储到一个全局变量中,以便在按下按钮时打印 问题是代码总是出错,我不知道如何更正它 这是我的代码: import UIKit import Eureka class ViewController: FormViewController { //Creating Global Variables var name: String = ""
import UIKit
import Eureka
class ViewController: FormViewController
{
//Creating Global Variables
var name: String = ""
var data: Date? = nil
@IBAction func testebutton(_ sender: Any)
{
print(name)
print(data)
}
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
form +++ Section()
<<< TextRow()
{
row in
row.title = "Name"
row.tag = "name"
}
<<< DateRow()
{
$0.title = "Birthdate"
$0.value = Date()
$0.tag = "date"
}
//Gets value from form
let row: TextRow? = form.rowBy(tag: "name")
let nome = row?.value
name = nome!
}
导入UIKit
进口尤里卡
类ViewController:FormViewController
{
//创建全局变量
变量名称:String=“”
var数据:日期?=零
@iAction func testebutton(\发送方:任何)
{
印刷品(名称)
打印(数据)
}
重写func viewDidLoad()
{
super.viewDidLoad()
//加载视图后,通常从nib执行任何其他设置。
form+++节()
一旦DateRow或TextRow发生更改,您需要使用.onChange
来更新您的值,或者您可以使用form.rowBy(tag:“tagName”)
直接访问值,并强制转换为可以访问.value
的正确行类型。在这个示例代码中,使用基本代码我使用这两种方法
import UIKit
import Eureka
class GettingDataViewController: FormViewController {
//Creating Global Variables
var name: String = ""
var data: Date? = nil
@IBAction func testebutton(_ sender: Any)
{
print(name)
print(data)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
form +++ Section()
<<< TextRow()
{
row in
row.title = "Name"
row.tag = "name"
}.onChange({ (row) in
self.name = row.value != nil ? row.value! : "" //updating the value on change
})
<<< DateRow()
{
$0.title = "Birthdate"
$0.value = Date()
$0.tag = "date"
}.onChange({ (row) in
self.data = row.value //updating the value on change
})
<<< ButtonRow(tag: "test").onCellSelection({ (cell, row) in
print(self.name)
print(self.data)
//Direct access to value
if let textRow = self.form.rowBy(tag: "name") as? TextRow
{
print(textRow.value)
}
if let dateRow = self.form.rowBy(tag: "date") as? DateRow
{
print(dateRow.value)
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
导入UIKit
进口尤里卡
类GettingDataViewController:FormViewController{
//创建全局变量
变量名称:String=“”
var数据:日期?=零
@iAction func testebutton(\发送方:任何)
{
印刷品(名称)
打印(数据)
}
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后执行任何其他设置。
form+++节()