How to set the current user in cell? Swift, Parse

筅森魡賤 提交于 2019-12-12 06:39:06

问题


Day, guys. Help me.I can not solve the problem for three days

I make an app look like an Instagram. I want to make sure that when you create a post, in cell of tableview, writing his nickname.

I am try this:

findSweeter.findObjectsInBackgroundWithBlock{
        (objects:[AnyObject]?, error:NSError?)->Void in
        if error == nil{
            let user:PFUser = (objects as NSArray).lastObject  as PFUser!
            cell1.usernamelabel.text = user.username
        }
    }
}

But thats issue: [AnyObject]? is not convertible to 'NSArray' & 'NSArray is not convertible to PFUser'

Help, pls. im using Parse.com


回答1:


I solved my problem so easly. I just changed PFUser variable in Data on Parse Clotd to String:

cell1.usernamelabel.text = sweet.objectForKey("usa") as? String




回答2:


The problem isn't the cast, but the fact that objects is an optional array: [AnyObject]?

You have to unwrap the array first:

findSweeter.findObjectsInBackgroundWithBlock{
    (objects:[AnyObject]?, error:NSError?)->Void in
    if error == nil && indexPath.row < objects?.count{
       var user: PFUser
       if let userObject = objects?[indexPath.row] {
          user = userObject as! PFUser
          cell1.usernamelabel.text = user.username
       }
    }
}


来源:https://stackoverflow.com/questions/29876944/how-to-set-the-current-user-in-cell-swift-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!