我有像
这样的代码@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var countryField: UITextField!
@IBOutlet weak var cityField: UITextField!
如何将所有这些项目放入数组中,以便我可以循环访问每个项目?
答案 0 :(得分:1)
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var countryField: UITextField!
@IBOutlet weak var cityField: UITextField!
...
let array = [emailField, countryField, cityField]
查看documentation on collection types
编辑:您可以拆分该数组的声明/ init
// outside any method
var array = [UITextField]?
// in viewDidLoad
self.array = [emailField, countryField, cityField]