嗨,我正在使用 Parse 开发一个应用程序,当用户创建一个帐户时,会有一个 UIPickerView 具有不同的字符串,用户必须从中进行选择。我试图将他们的选择保存在一个字符串中。我已经可以使用它了,但这可以保存一个数字而不是一个字符串。
let myRank = picker.selectedRowInComponent(0)
当我尝试
let myRank = pickerArray[row]
我收到一条错误消息“使用未解析的标识符“行”。我猜这是因为范围,但我不知道如何解决它!
这是我的代码:
let pickerArray: NSArray = ["- Välj din kompetens -", "Assistent", "Instruktör", "Biträdande Kurschef", "Kurschef"]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerArray.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return "\(pickerArray[row])"
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
// selected value in Uipickerview in Swift
let rank = pickerArray[row]
}
@IBAction func registerButtonPressed(sender: UIButton) {
let myRank = pickerArray[row]
var user = PFUser()
user.username = email
user.password = password
user.email = email
user[PF_USER_RANK] = myRank
user[PF_USER_EMAILCOPY] = email
user[PF_USER_FULLNAME] = name
user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError!) -> Void in
if error == nil {
PushNotication.parsePushUserAssign()
ProgressHUD.showSuccess("Succeeded.")
self.dismissViewControllerAnimated(true, completion: nil)
} else {
if let userInfo = error.userInfo {
ProgressHUD.showError(userInfo["error"] as String)
}
}
}
}