首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“[AnyObject]?”不可转换为“NSArray”(xcode,NSArray)

“[AnyObject]?”不可转换为“NSArray”(xcode,NSArray)
EN

Stack Overflow用户
提问于 2015-08-19 02:21:49
回答 1查看 275关注 0票数 0

错误在let USER:PFUser中..。它运行良好,但当我更新Xcode时,出现了这个问题。未显示用户名的名称。

代码语言:javascript
复制
        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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-19 02:29:28

您需要确保从解析中返回数组。

你可以用这个:

代码语言:javascript
复制
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
            })
            }

        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32085524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档