[英]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.