Please better format the code you post:
override func viewDidAppear( animated: Bool) { super.viewDidAppear(animated)
loadData() // this is my function that queries and reloads data }
I have also a textField from which a message is captured updates the database and calls loadData() as follows:
@IBAction func composeButton( sender: Any) {
//inputAlert()
if (feedInputField.text != "" ) {
let reqType = Int(reqTypeIndex.text ?? "") ?? 0
AddFeedbacks(message: feedInputField.text ?? "", taskId: idTask?.text ?? "", atype: reqType)
loadData()
feedInputField.text = ""
}
}
func r_feedback(rtaskId: String) {
var singleFeed = myFeedback()
self.arrayOfFeedback.removeAll()
queryFeedback(taskId: rtaskId).findObjectsInBackground { (objects, error) in
if let objects = objects {
if (objects.count 0) {
for eachFeed in objects {
singleFeed.feedDate = eachFeed.createdAt!
singleFeed.userNameFrom = eachFeed["UserNameFrom"] as? String
singleFeed.feedMessage = eachFeed["TaskFeedback"] as? String
singleFeed.atype = eachFeed["AType"] as? Int
self.arrayOfFeedback.append(singleFeed)
}
} else {
singleFeed.feedDate = nil
singleFeed.userNameFrom = ""
singleFeed.feedMessage = ""
singleFeed.atype = nil
}
self.fTableView.reloadData()
}
}
}
What is AddFeedbacks ?
Note: name should start with lowerCase.
Problem : When the app first loads, it loads existing messages in the database.
And if I add a new message from the feedInputField, the tableView is not updated but if I added a second message, it then displays both messages. From there, it starts updating normaly. The issue is only when i load the app and after that it works.
Problem could be that addFeedbacks executes in another thread asynchronously. And completes after you reload.