错误在let USER:PFUser中..。它运行良好,但当我更新Xcode时,出现了这个问题。未显示用户名的名称。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let postcells: postsTableViewCell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! postsTableViewCell
let Post:PFObject = self.PostData.objectAtIndex(indexPath.row) as! PFObject
postcells.postTimetextView.text = Post.objectForKey("Content") as! String
var dateFormatter:NSDateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.NoStyle
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
postcells.timeStamp.text = dateFormatter.stringFromDate(Post.createdAt!)
var findPostedBy:PFQuery = PFUser.query()!
findPostedBy.whereKey("objectId", equalTo: Post.objectForKey("Postedby")!)
findPostedBy.findObjectsInBackgroundWithBlock{
(objects, error) -> Void in
if error == nil {
let USER:PFUser = (objects as NSArray).lastObject as! PFUser
postcells.usernameLabel3.text = USER.username
}
}
return postcells
}发布于 2015-08-19 02:29:28
您需要确保从解析中返回数组。
你可以用这个:
findPostedBy.findObjectsInBackgroundWithBlock{
(objects, error) -> Void in
if error == nil {
if objects?.count > 0 {
let USER:PFUser = objects!.last as! PFUser
// Avoid updating the UI on a background thread
dispatch_async(dispatch_get_main_queue(), { () -> Void in
postcells.usernameLabel3.text = USER.username
})
}
}
}https://stackoverflow.com/questions/32085524
复制相似问题