Swift里使用了Eureka,如何将TextRow里面的值调用出来?

本人超级小小白,现在是这样的,我安装了Eureka开源框架并且用它创建了3行text row,用户填入内容后,我需要app里调用这3行text row里用户输入的值,试了很久都不行。
以下是代码:


import UIKit
import Eureka
class ViewController: FormViewController{

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    //Set title for Navi Bar
    self.title="Data Manager"
    
    //Add one Section without title
    form +++ Section ("")
    
    //Add Text Row
        <<< TextRow("FirstTag"){ row1 in
            row1.title = "Project code"
            row1.placeholder = "Enter Project Code here"
            }.onChange { row1 in
                print(row1.value)}
        <<< TextRow("SecondTag"){ row2 in
            row2.title = "Username"
            row2.placeholder = "Enter Username here"
            }.onChange { row2 in
                print(row2.value)}
        <<< TextRow("ThirdTag"){ row3 in
            row3.title = "Password"
            row3.placeholder = "Enter Password here"
            }.onChange { row3 in
            print(row3.value)}
    
    // add "Log on" button
    let myFirstButton = UIButton()
    myFirstButton.setTitle("Log In", for: .normal)
    myFirstButton.setTitleColor(UIColor.white, for: .normal)
    myFirstButton.backgroundColor = UIColor.blue
    myFirstButton.frame = CGRect(x: 65, y: 260, width: 250, height: 50)
    myFirstButton.addTarget(self, action: #selector(self.pressed), for: .touchUpInside)
    self.view.addSubview(myFirstButton)
    
    
}

    func pressed() {
        let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        
        alertController.addAction(okAction)
        
        self.present(alertController, animated: true, completion: nil)
        
        print(TextRow.init(tag: "FirstTag").value)
    }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

在viewLoad函数里面的onChange函数是可以的,可以print出返回值。但是我试图加了一个Alert message,目的是出现这个message 的时候可以print返回值,也就是这段代码,就报错了
print(TextRow.init(tag: "FirstTag").value)

不知道有人知道吗?小妹在此谢过了!!

阅读 2.5k
1 个回答
✓ 已被采纳新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏