使用parse和swift跟随的用户列表

我已经从2周开始研究它,我喜欢app,用户可以使用Parse后端登录和登录。 现在,在signUp为下一个名为“userListTableViewController”的屏幕制作了一个segue之后,将允许用户关注已经存在的用户。 现在我尝试在NSMutableArray检索数据并显示如下:

 import UIKit class userListTableViewController: UITableViewController { var data:NSMutableArray = NSMutableArray() var isFollowing = [PFObject:Bool]() func loadData() { data.removeAllObjects() isFollowing.removeAll(keepCapacity: true) var userQuery = PFUser.query() userQuery?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in if error != nil { } else { if let objects = objects { for object in objects { if let user = object as? PFObject { if user.objectId != PFUser.currentUser()?.objectId { self.data.addObject(user) var followerQuery: PFQuery = PFQuery(className: "Followers") followerQuery.whereKey("follower", equalTo: PFUser.currentUser()!) followerQuery.whereKey("user", equalTo: user) followerQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in if let objects = objects { if objects.count > 0 { self.isFollowing[user] = true } else { self.isFollowing[user] = false } } if self.isFollowing.count == self.data.count { self.tableView.reloadData() } }) } } } } } }) } override func viewDidLoad() { super.viewDidLoad() loadData() } /* var array:NSMutableArray = NSMutableArray(array: self.data.reverseObjectEnumerator().allObjects) self.data = array as NSMutableArray self.tableView.reloadData() */ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // #warning Potentially incomplete method implementation. // Return the number of sections. return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete method implementation. // Return the number of rows in the section. return data.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let myCell = tableView.dequeueReusableCellWithIdentifier("users", forIndexPath: indexPath) as! userListTableViewCell let userData:PFObject = self.data.objectAtIndex(indexPath.row) as! PFObject myCell.fullName.text = userData["objectId"] as! String! myCell.genderLabel.text = userData["gender"] as! String! // var array:NSMutableArray = NSMutableArray(array: self.data.reverseObjectEnumerator().allObjects) // self.data = array as NSMutableArray let followedId = userIds[indexPath.row] if isFollowing[followedId] == true { // ERROR!! not able to use followedId here.. how should i give a value so that it will check the particular user's objectId and isFollowing Bool value. myCell.followButtton.setTitle("unfollow", forState: UIControlState.Normal) } else { myCell.followButtton.setTitle("follow", forState: UIControlState.Normal) } userData["profilePicture"]?.getDataInBackgroundWithBlock({ (data, error) -> Void in if let downloadeImage = UIImage(data: data!) { myCell.dp.image = downloadeImage } myCell.followButtton.tag = indexPath.row myCell.followButtton.addTarget(self, action: "followButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside) }) return myCell } // IBActions.. func followButtonTapped(sender: UIButton){ let userData:PFObject = self.data.objectAtIndex(sender.tag) as! PFObject let followedId = userData["objectId"] as! PFObject if isFollowing[followedId] == false { isFollowing[followedId] = true sender.setTitle("unfollow", forState: UIControlState.Normal) let getObjectByIdQuery = PFUser.query() getObjectByIdQuery?.whereKey("objectId", equalTo: userData.objectId!) getObjectByIdQuery?.getFirstObjectInBackgroundWithBlock({ (foundObject:PFObject?, error:NSError?) -> Void in if let object = foundObject { var followers:PFObject = PFObject(className: "Followers") followers["user"] = object followers["follower"] = PFUser.currentUser() followers.saveInBackgroundWithBlock({ (success, error) -> Void in if error != nil { println(error) } else { println("saved") } }) } }) } else { isFollowing[followedId] = false sender.setTitle("follow", forState: UIControlState.Normal) var query:PFQuery = PFQuery(className: "Followers") query.whereKey("follower", equalTo: PFUser.currentUser()!) query.whereKey("user", equalTo: data[sender.tag]) query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in if let objects = objects { for object in objects { object.deleteInBackgroundWithBlock({ (success, error) -> Void in if error != nil { println(error) } else { println("deleted") } }) } } }) } } } 

在代码中显示问题作为注释..或者你能告诉我一些比这更好的方法..我也尝试在数组中检索数据,我也遇到了“跟随”按钮的问题。 您可以在此处查看问题。 从Parse检索对象时无法正确重新加载数据

请帮帮我..谢谢..

编辑:我只想制作具有性别全名和个人资料图片的用户列表,并希望允许用户使用每个单元格上的“跟随”按钮关注它们。如果应用程序重新启动,则已经使用过的用户如果当前用户需要,则必须将当前用户标记为“取消关注”以取消关注用户。