Swift Parse查询如何在对象中创建uialertview?

时间:2015-08-06 00:20:55

标签: ios swift parse-platform uialertview

我正在进行解析查询,我希望在for object in objects {}完成后执行UIAlertView!如果我将alertview放在for object in objects{//here}内,没有任何反应,我怎样才能检测到for objects in objects {}完成然后我显示alertview ??

代码如下所示:

var query = PFUser.query()

query = PFQuery(className: "_User")

query.findObjectsInBackgroundWithBlock {

(object: [AnyObject]!, error:NSError?) -> Void in


for object in objects {

// alertview here not working, How can i make it after this loop done?


}

}

任何帮助?

1 个答案:

答案 0 :(得分:0)

var query = PFUser.query()

query = PFQuery(className: "_User")

// Heads up, entering background thread, may take some time to update the UI, maybe add an activity indicator even?
query.findObjectsInBackgroundWithBlock {

(objects: [AnyObject]?, error: NSError?) -> Void in

for object in objects as! [PFObject] {

// alertview here not working, How can i make it after this loop done?
// This would make an alert for every found object

}

// Anything after the for loop will happen after it completes, so if you put something here it will execute, suggest dispatching anything UI related to the main queue 

     dispatch_async(dispatch_get_main_queue(), { () -> Void in

        // visual interface stuff should happen here

    })

}