简体   繁体   English

在解析中使用用户的朋友列表更新Tableview

[英]Update Tableview with user's friend list in parse

I'm using Parse to add friend's username to current user object with PFRelation and I want to retrieve it to appear at friend list view controller. 我正在使用Parse通过PFRelation将朋友的用户名添加到当前用户对象中,我想检索它以显示在朋友列表视图控制器中。 This is my code for retrieving current user friend list's object and updating tableview to show current user's latest friend list. 这是我的代码,用于检索当前用户朋友列表的对象并更新tableview以显示当前用户的最新朋友列表。 My class in Parse that save all my app's registered user is "User". 我在Parse中保存我所有应用程序注册用户的类是“ User”。
Here's my code in swift 这是我的代码迅速

var userArray: [String] = []
var usernames:[String] = [""]
var userids :[String] = [""]

override func viewDidLoad() {
    super.viewDidLoad()
    var query = PFUser.query()
    var currentUser = PFQuery(className:"User")
    currentUser.whereKey("currentUser", equalTo: PFUser.currentUser())

    currentUser.findObjectsInBackgroundWithBlock({ (objects:PFObject, error:NSError) -> Void in  // <- error here says that Expression resolves to an unused function
        if objects != nil { // <- error here says that cannot invoke != with an argument list of type(PFObject,NilLiteralConvertible)
            let users = objects
            self.users.removeAll(keepCapacity: true)
            self.usernames.removeAll(keepCapacity: true)

            for object in users {
                if let user = object as? PFUser {
                    userArray.append(user.username)
                }
            }
            else {  // <- error here says that Expected expression
                println("Error")
            }
        }
    }
}

The problem is that my tableview shows nothing, it's just an empty tableview but when I check at parse.com, the current user's relation exists and all the user's that I've add exist in that relation so the problem is to retrieve current user's object and update the tableview. 问题是我的表视图什么都没有显示,只是一个空的表视图,但是当我在parse.com上检查时,当前用户的关系存在,并且我添加的所有用户关系都存在于该关系中,因此问题在于检索当前用户的对象并更新表格视图。
Any help is appreciated and let me know if you need any additional information. 感谢您的帮助,如果您需要其他任何信息,请与我们联系。

Thank you! 谢谢!

Since you're getting data asynchronously the UI does not know when to update. 由于您要异步获取数据,因此UI不知道何时更新。 You need to update the UI once you have all of your data. 拥有所有数据后,您需要更新UI。

Try putting self.tableView.reloadData() after the for loop in your findObjectsInBackgroundWithBlock block 尝试将self.tableView.reloadData()放置在findObjectsInBackgroundWithBlock块中的for循环之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户的朋友列表tableview为空,解析查询未返回任何数据 - User's friend list tableview is empty and parse query did not return any data 如何使用户能够通过朋友的用户名添加朋友并在表视图中快速显示用户的朋友列表 - How to enable user to add friends via friend's username and display user's friend list in tableview with swift 使用解析在tableview中检索和显示用户的对象,但tableview不会更新 - Using parse to retrieve and show user's object in tableview but tableview won't update 函数应将用户添加到Firebase中其他朋友节点的列表中,但返回nil - function should add user to a list in other friend's node in Firebase but instead it returns nil 如何在Facebook iOS SDK中获取Facebook用户的完整朋友列表 - How to fetch Facebook user's full friend list in Facebook iOS SDK Qucikblox:如何在好友列表中添加用户? - Qucikblox : How to add user in friend list? 用户的Facebook状态到tableview - User's Facebook Status to tableview 解析-如何在将更多数据添加到解析数据库时更新tableView? - Parse - How to update tableView as more data is added to the parse database? 快速保存当前用户的消息列表以进行解析 - Save current user's message list in parse with swift Google+不会返回用户的朋友的电子邮件地址 - Google+ does not return user's friend's email address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM