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

查看:136
本文介绍了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)

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

解决方案

ms解决了,把值放在dict里面传递
http://stackoverflow.com/ques...

这篇关于Swift里使用了Eureka,如何将TextRow里面的值调用出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆