I'm trying to reload my pickerView after loading data from a query. However the pickerView is not reloading. I want the subjectPickerView to reload after subjectPickOption is appended.
query = PFQuery(className:"Subject")
query.addAscendingOrder("subjectId")
query.getObjectInBackgroundWithId(object.objectId!) {
(subject: PFObject?, error: NSError?) -> Void in
if error == nil && subject != nil {
self.subjectPickOption.append(subject!["subject"] as! String)
self.subjectPickerTextField.userInteractionEnabled = true
} else {
print("Error: \(error!) \(error!.userInfo)")
}
}
Where should I place my self.SubjectPickerView.reloadAllComponents()?
答案 0 :(得分:0)
Under the line:
self.subjectPickerTextField.userInteractionEnabled = true
add your reloadAllComponents, but most importantly you need to run it on the main thread as your data call is on a background thread and when you change UI things it needs to be in the main thread:
...
dispatch_async(dispatch_get_main_queue(),{
self.SubjectPickerView.reloadAllComponents()
}
...