Reputation: 161
im new to iOS and developing twitter like app using tutorials.
people can make tweets from their account. and it get display in home page.
at the moment to home page all the tweets and everything works well except username. im getting nil
this is what i have tried
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:SpreadTableViewCell = tableView!.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SpreadTableViewCell
let spread:PFObject = self.LiveFeedData.objectAtIndex(indexPath.row) as! PFObject
//----------This Content Works fine ----------------
cell.spreadTextView.text = spread.objectForKey("content") as! String
//Spreader
var findSpreader:PFQuery = PFUser.query()!
findSpreader.whereKey("objectId", equalTo: spread.objectForKey("spreader")!)
findSpreader.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]?, error:NSError?)-> Void in
if error==nil{
let user = (objects as! [PFUser]).last
//but this one giving me nil
cell.username.text = user?.username
}
}
return cell
}
Upvotes: 0
Views: 202
Reputation: 7373
Try this:
var user = spread.objectForKey("spreader") as! PFUser
user.fetchIfNeededInBackgroundWithBlock { (obj: PFObject?, error: NSError?) -> Void in
if obj != nil {
var fetchedUser = obj as! PFUser
var username = fetchedUser["username"] as! String
println(username)
}
}
Upvotes: 1