【发布时间】:2016-05-01 12:21:38
【问题描述】:
let userQuery = PFUser.query()
userQuery!.whereKey("username", equalTo: userUsername)
userQuery!.findObjectsInBackgroundWithBlock({ (result:[PFObject]?, error:NSError?) in
currentProfilePageUser = result![0] as! PFUser
})
这是我的代码。我正在尝试仅使用用户名获取PFUser。但是,我在findObjectsInBackgroundWithBlock 中添加了断点,发现它没有被调用。因此,我无法接收我的数据。为什么findObjectsInBackgroundWithBlock 没有被调用?
let query = PFQuery(className: "Follow")
query.whereKey("followFrom", equalTo: PFUser.currentUser()!.objectId!)
query.whereKey("followingTo", equalTo: currentProfilePageUser)
query.findObjectsInBackgroundWithBlock { (result:[PFObject]?, error:NSError?) in
if result == nil{
print("currentuser is not following this user")
self.followButtonTitle.setTitle("Follow", forState: .Normal)
}else{
print("currentuser is follwing this user")
self.followButtonTitle.setTitle("Unfollow", forState: .Normal)
}
}
由于一些非常奇怪的原因,第一个 findObjectsInBackgroundWithBlock 现在可以工作,但另一个没有被调用。这很奇怪。
【问题讨论】:
-
它可能正在被调用,但由于它是“inBackground”,这意味着它是在后台线程上调用的。尝试测试错误并为它们添加打印语句。您应该会看到其中至少有一个被调用了。
标签: ios swift parse-platform swift2 pfquery