Ios 主线程pfquerytableviewcontroller

Ios 主线程pfquerytableviewcontroller,ios,swift,xcode,parse-platform,swift3,Ios,Swift,Xcode,Parse Platform,Swift3,我有一个pfquery tableview控制器,该控制器在类中有许多pfobjects,这些pfobjects正在我的pfquerytableview控制器中加载。我必须解决这些问题。当我刷新我的表视图时,我在我的调试器“警告:在主线程上正在执行一个长时间运行的操作”中得到了这个错误。 在警告BlockingOperationMainThread()以进行调试时中断。“。当我尝试在我的tableview中滑动时,tableview会滞后并且滑动非常缓慢。我假设发生这种情况是因为数据正在主线程上

我有一个pfquery tableview控制器,该控制器在类中有许多pfobjects,这些pfobjects正在我的pfquerytableview控制器中加载。我必须解决这些问题。当我刷新我的表视图时,我在我的调试器“警告:在主线程上正在执行一个长时间运行的操作”中得到了这个错误。 在警告BlockingOperationMainThread()以进行调试时中断。“。当我尝试在我的tableview中滑动时,tableview会滞后并且滑动非常缓慢。我假设发生这种情况是因为数据正在主线程上加载。这是我的密码。有人能告诉我如何解决这两个问题吗。非常感谢。谢谢

class ProductTableViewController: PFQueryTableViewController{
override func queryForTable() -> PFQuery<PFObject> {
    var query : PFQuery<PFObject>!


        query = PFQuery(className: "Products")
        query.includeKey("User")
        query.limit = 25
        query.skip = 25

                query.order(byAscending: "createdAt")

}


override func viewDidLoad() {
    super.viewDidLoad()
    let nib = UINib(nibName: "ProductTableViewCell", bundle: nil)
    tableView.register(nib, forCellReuseIdentifier: reuseIdentifier)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
    let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! ProductTableViewCell

    if let files : [PFFile] = object?["Images"] as? [PFFile] {
        cell.ProductImage.file = files.first
        cell.ProductImage.loadInBackground()
    }

   }
  }
类ProductTableViewController:PFQueryTableViewController{
重写func queryForTable()->PFQuery{
var查询:PFQuery!
query=PFQuery(类名:“产品”)
query.includeKey(“用户”)
query.limit=25
query.skip=25
query.order(升序:“createdAt”)
}
重写func viewDidLoad(){
super.viewDidLoad()
让nib=UINib(nibName:“ProductTableViewCell”,bundle:nil)
注册表(nib,forCellReuseIdentifier:reuseIdentifier)
}
重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath,object:PFObject?->pftableview单元格{
让cell=tableView.dequeueReusableCell(标识符为:reuseIdentifier,for:indepath为indepath)作为!ProductTableViewCell
如果让文件:[PFFile]=对象?[“图像”]作为?[PFFile]{
cell.ProductImage.file=files.first
cell.ProductImage.loadInBackground()的
}
}
}

为什么不使用普通的tableViewController

var show = 0
let maxload = 250
var objects = [PFObject]()

func loaddata() {
    self.objects.removeAll(keepingCapacity: false)
    self.show = 25

    let query = PFQuery(className:"Ledger")
    query.limit = self.maxload
    query.findObjectsInBackground {
        (objects: [PFObject]?, error: Error?) -> Void in
        if error == nil {
            if let objects = objects as [PFObject]! {
                for object in objects {
                    self.objects.append(object)
                }
                //reload TableView
                self.tableView.reloadData()
                print("retrieved \(self.objects.count)")

            }
        }
    }
}

@IBAction func refreshButton(_ sender: AnyObject) {
    loaddata()
    self.tableView.reloadData()
}

func numberOfSections(in tableView: UITableView) -> Int {
    if self.objects.count <= 0 {
        return 0
    } else {
        if show > self.objects.count {
            return self.objects.count
        } else if show > maxload {
            return maxload
        } else {
            return show
        }
    }
}


func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if (indexPath as NSIndexPath).section == self.show - 1 {
        self.show += 25
        print("showing more data")
    }
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewController

    if self.objects.count - 1 > (indexPath as NSIndexPath).section {
        let objects = self.objects[(indexPath as NSIndexPath).section] 
    }

    return cell
}
var show=0
设maxload=250
变量对象=[PFObject]()
func loaddata(){
self.objects.removeAll(保留容量:false)
self.show=25
let query=PFQuery(类名:“分类账”)
query.limit=self.maxload
query.findObjectsInBackground{
(对象:[PFObject]?,错误:错误?->Void in
如果错误==nil{
如果让objects=对象作为[PFObject]{
对于对象中的对象{
self.objects.append(对象)
}
//重新加载TableView
self.tableView.reloadData()
打印(“检索\(self.objects.count)”)
}
}
}
}
@iAction func刷新按钮(\uSender:AnyObject){
loaddata()
self.tableView.reloadData()
}
func numberOfSections(在tableView:UITableView中)->Int{
如果self.objects.count self.objects.count{
返回self.objects.count
}否则,如果显示>最大负载{
返回最大负载
}否则{
回归演出
}
}
}
func tableView(tableView:UITableView,willDisplay单元格:UITableView单元格,forRowAt indexath:indexath){
if(indepath作为nsindepath.section==self.show-1{
self.show+=25
打印(“显示更多数据”)
}
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回1
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell=tableView.dequeueReusableCell(标识符为“cell”,for:indexPath)作为!TableViewController
如果self.objects.count-1>(indepath作为nsindepath){
让objects=self.objects[(indepath作为nsindepath.section]
}
返回单元
}

我曾经涉猎过Android。移动操作系统框架讨厌开发者将重要任务放在UI线程中。在Android中,我们实现AsynchTask在另一个线程上工作。阻止您挂断UI。我不知道这到底是什么,我不知道该怎么办。我不认为parse会为pfquerytableviewcontroller创建框架,因为它肯定会在主线程上发生操作和崩溃。有一个解决方案我还不知道。试着看看我刚刚知道的,他们在本指南中提到了PFQuery的后台查询功能。