从文本字段数组获取值 [英] Get values from a textfield array
本文介绍了从文本字段数组获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想访问我的textfield数组的值,但由于我创建的数组带有标签而感到困惑.因此,有人知道如何获取我创建的列表(数组)的值吗?
I would like to access the values of my textfield array but confused as the array I created is with tags. So anyone knows how to get the value of the list (array) I created?
我想在其中创建一个函数:获取列表中文本字段的值按标签对它们进行排序获取每个文本字段的值将它们串联成一个字符串
I want to create a function where I : Get the value of the textfields on a list Sort them by tags get the value of each individual textfield concatenate them in a string
推荐答案
假设您有以下数组,
var txtArray:[UITextField] = [UITextField]()
for i in 0...4 {
let txtField = UITextField(frame: .zero)
txtField.text = "\(i)"
txtField.tag = i
txtArray.append(txtField)
}
要获取值,您必须执行以下操作
To get values you have to do following,
let sorted = txtArray.sorted { $0.tag < $1.tag }
let values = sorted.map { return $0.text! }
let test = values.joined(separator: " ")
print(test)
输出将为
0 1 2 3 4
这篇关于从文本字段数组获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文