我有一个UIPickerView我需要将用户选择保存到Parse。我尝试了一百万种不同的东西,只是让我的专栏空白。我有什么想法我做错了吗?信息只是没有保存到Parse,我知道UIPicker可以工作,因为标签更新。我搜索了谷歌和堆栈,但我的代码看不出来有什么问题?
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var pickerView: UIPickerView!
@IBOutlet weak var pickedLabel: UILabel!
var pickerDataSource = ["Car", "Bus", "Train", "Plane", "Boat"]
override func viewDidLoad() {
super.viewDidLoad()
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return self.pickerDataSource.count;
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return self.pickerDataSource[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
PFUser.currentUser()?["PickerColumn"] = self.pickerDataSource[row];
self.pickedLabel.text = "Your choice: \(self.pickerDataSource[row])"
PFUser.currentUser()?.saveInBackground()
}
我也试过这个:
var pickerSave: String?
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
pickerSave = pickerDataSource[row]
self.pickedLabel.text = "Your choice: \(self.pickerDataSource[row])"
}
@IBAction func next(sender: AnyObject) {
PFUser.currentUser()?["pickerColumn"] = pickerSave
self.performSegueWithIdentifier("next", sender:self)
PFUser.currentUser()?.saveInBackground()
}
答案 0 :(得分:0)
如果您的标签正在更新,那么您的选择器就可以了。您发出的是PFUser类。 PFUser.currentUser()是否按预期返回字典?设置“pickerColumn”后,你可以在控制台上打印出它的值吗?
以下是否有效:
PFUser.currentUser()?["pickerColumn"] = "1"
PFUser.currentUser()?.saveInBackground()
那些特定的线条正在破碎。
答案 1 :(得分:0)
所以看起来你试图将选择器中的值保存到解析_User类中。无论如何,我不建议将它保存在那里。我假设您正在使用mongoDB,这是一个架构问题。所以我要做的是创建一个用于存储这些数据的新类。
我会这样声明。
sed 's/^com\.enterprise\.project\.AERO_CARRIERS[[:blank:]]*=[[:blank:]]*.\{1,\}/&|JJ|PZ/'