Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS SWIFT:Pull to Refresh功能不更新TableView_Ios_Iphone_Swift_Uitableview_Parse Platform - Fatal编程技术网

iOS SWIFT:Pull to Refresh功能不更新TableView

iOS SWIFT:Pull to Refresh功能不更新TableView,ios,iphone,swift,uitableview,parse-platform,Ios,Iphone,Swift,Uitableview,Parse Platform,我在TableView控制器中有pull-to-refresh功能,它列出了所有用户名和当前用户的跟踪对象(每行末尾有一个复选标记)。这是我的刷新功能: var refresher: UIRefreshControl! func refresh() { var query = PFUser.query() query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in i

我在TableView控制器中有pull-to-refresh功能,它列出了所有用户名和当前用户的跟踪对象(每行末尾有一个复选标记)。这是我的刷新功能:

  var refresher: UIRefreshControl!
    func refresh() {
    var query = PFUser.query()
    query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
        if let users = objects {
            self.usernames.removeAll(keepCapacity: true)
            self.userids.removeAll(keepCapacity: true)
            self.isFollowing.removeAll(keepCapacity: true)

            for object in users {
                if let user = object as? PFUser {
                    if user.objectId! != PFUser.currentUser()?.objectId {
                        self.usernames.append(user.username!)
                        self.userids.append(user.objectId!)

                        var query = PFQuery(className: "followers")
                        query.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
                        query.whereKey("following", equalTo: user.objectId!)
                        query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

                            if let objects = objects {
                                if objects.count > 0 
                                {
                                self.isFollowing[user.objectId!] = true
                                }
                                 else 
                                {
                                 self.isFollowing[user.objectId!] = false

                                }
                            }

                      if self.isFollowing.count == self.usernames.count
                          {
                                 self.tableView.reloadData()
                                self.refresher.endRefreshing()

                            }
                        })

                    }
                }

            }

        }

    })

}
它在我的viewDidLoad中被称为:

  override func viewDidLoad() {
    super.viewDidLoad()
    //pull to refresh funcationlity
    refresher = UIRefreshControl()
    refresher.attributedTitle = NSAttributedString(string: "Pull to refresh")
    refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refresher)
    refresh()

}
问题是,当我从Parse.com数据库手动删除一个项目,并在列表视图中拉入刷新时,它不会更新。以下是我的tableview功能:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
    cell.textLabel?.text = usernames[indexPath.row]
    let followedObjectId = userids[indexPath.row]
    if isFollowing[followedObjectId] == true {
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark
    }

       return cell
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
            let followedObjectId = userids[indexPath.row]
    if isFollowing[followedObjectId] == false {
        isFollowing[followedObjectId] = true
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark
        var following = PFObject(className: "followers")
        following["following"] = userids[indexPath.row]
        following["follower"] = PFUser.currentUser()?.objectId
        following.saveInBackground()
    } 
   else 
     {
        isFollowing[followedObjectId] = false
        cell.accessoryType = UITableViewCellAccessoryType.None
        var query = PFQuery(className: "followers")
        query.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
        query.whereKey("following", equalTo: userids[indexPath.row])
        query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
            if let objects = objects {
                for object in objects {
                    object.deleteInBackground()
                    print(object)
                }
            }
        })
    }
}

看起来它应该可以工作了…我在想,由于您在后台线程上发送网络调用,所以您的UI在查询返回之前正在更新。尝试抓取要更新的主队列?看起来应该可以工作…我认为,由于您在后台线程上发送网络调用,因此您的UI在查询返回之前正在更新。是否尝试抓取要更新的主队列?