假设我有以下异步查询:
var kittens: [PFObject]!
self.tempView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "pushToView"))
var query = PFQuery(className: "Kittens")
query.findObjectsInBackgroundWithBlock({ (objects, error) in
if let kittenObjects = objects as? [PFObject] {
self.kittens = kittenObjects
}
})
我有一个呈现视图控制器的方法:
func pushToView() {
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController: KittensViewController = mainStoryboard.instantiateViewControllerWithIdentifier("kittensViewController") as! KittensViewController
viewController.kittens = self.kittens
self.presentViewController(viewController, animated: true, completion: nil)
}
因为我在异步查询块内进行设置,所以当我尝试访问呈现的视图控制器(它始终为空)self.kittens
时,它显然不起作用。self.kittens
让这样的事情发挥作用的最佳方法是什么?