When the post button is pressed, the function below executes. In the function, all the objects that are retrieved using the Parse backend are appended to the groupConversation
array, which is a global array. However, when I reference the array in the UITableViewController
that is popped to towards the end of the function and use println()
to print the content of the array, the array is empty. However, when I use println()
in the UIViewController
that contains this function the array is shown to contain one object. In the console, the println()
of the UITableViewController
that is popped to once the button is pressed, is executed before the println()
of the UIViewController
that contains the function below. How can I make the functon below execute completely before popping to the UITableViewController
.
@IBAction func postButtonPressed(sender: AnyObject) {
//Adds Object To Key
var name=PFObject(className:currentScreen)
name["userPost"] = textView.text
name.saveInBackgroundWithBlock {
(success: Bool!, error: NSError!) -> Void in
if success == true {
self.textView.text=""
} else {
println("TypeMessageViewController Error")
}
}
//Gets all objects of the key
var messageDisplay = PFQuery(className:currentScreen)
messageDisplay.selectKeys(["userPost"])
messageDisplay.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil{
for object in objects {
var textObject = object["userPost"] as String
groupConversation.append(textObject)
}
} else {
// Log details of the failure
}
println("Type message \(groupConversation)")
}
navigationController!.popToViewController(navigationController!.viewControllers[1] as UIViewController, animated: true)
}
Aucun commentaire:
Enregistrer un commentaire