我尝试对注册视图控制器进行编程,并使用UIPickerView
进行国家/地区选择。问题是,当我试图将选择器国家传递给Parse以保存输入时,Xcode给我一个错误。为什么Xcode不允许我使用所选数据进行解析?错误在最后一行。
任何帮助人员?
@IBOutlet var usernameTextField: UITextField!
@IBOutlet var fullnameTextField: UITextField!
@IBOutlet var emailTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!
@IBOutlet var phonenumberTextField: UITextField!
@IBOutlet var countryPicker: UIPickerView!
let countryData: [String] = ["Saudi Arabia", "Turkey"]
@available(iOS 2.0, *)
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return countryData.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let countrySelect = countryData[row]
print(countrySelect)
}
override func viewDidLoad() {
super.viewDidLoad()
countryPicker.dataSource = self
countryPicker.delegate = self
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func signUpAction(sender: AnyObject) {
// Declare user object
let newUser = PFUser()
let fullName = fullnameTextField.text!
let username = usernameTextField.text!
let email:String = emailTextField.text!
let password:String = passwordTextField.text!
let phoneNumber:Int? = Int(phonenumberTextField.text!)
// Passing arguments
newUser.username = username
newUser["fullName"] = fullName
newUser.email = email
newUser.password = password
newUser["phoneNumber"] = phoneNumber! as Int
newUser["country"] = countryData [row]
答案 0 :(得分:0)
根据您的comment错误是“未解析的标识符行”:
您永远不会声明名为row
的变量,但您正在使用它。您可以使用正确的数组索引替换此未定义变量的使用,该索引将为您提供countryData
变量中的国家/或者确保在您的函数中实际声明并可访问该行。