我在此代码的这一行收到此错误消息:
findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("sweeter")!.objectId)
错误:
不能使用类型'的参数调用'whereKey'(String, equalTo:String?!)'
以下是我在cellForRowAtiIndex
路径中使用的代码,用于检索要在单元格中显示的个人资料图片,个人资料名称和内容:
var findSweeter:PFQuery = PFUser.query()!
findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("sweeter")!.objectId)
findSweeter.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]?, error:NSError?)->Void in
if error == nil{
let user:PFUser = (objects as! NSArray).lastObject as! PFUser
cell.usernameLabel.text = user.username
UIView.animateWithDuration(0.5, animations: {
cell.sweetTextView.alpha = 1
cell.timestampLabel.alpha = 1
cell.usernameLabel.alpha = 1
cell.profilePic.alpha = 1
})
}
}
非常感谢任何解决此问题的方法。使用Xcode 6.3.2。提前谢谢!
答案 0 :(得分:0)
尝试在查询之前展开可选变量。
if let sweeter: PFObject = sweet.objectForKey("sweeter") as? PFObject {
var findSweeter:PFQuery = PFUser.query()!
findSweeter.whereKey("objectId", equalTo: sweeter.objectId)
findSweeter.findObjectsInBackgroundWithBlock {
// ...
}
}