Long-运行 正在主线程上执行操作

Long-Running Operation is being executed on main thread

这个问题我已经看过好几次了,但还是没有找到解决办法。 我正在使用解析托管 sdk @ back4app.com

收到此错误:

Warning: A long-running operation is being executed on the main thread. Break on warnBlockingOperationOnMainThread() to debug.

在我的 home.swift 文件中,代码是:

func queryPosts(text:String) {
    showHUD()

    let query = PFQuery(className: POSTS_CLASS_NAME)

    if text != "" {
        let keywords = text.componentsSeparatedByString(" ") as [String]
        query.whereKey(POSTS_QUOTE, containsString: "\(keywords[0])")
    }

    query.orderByDescending("createdAt")
    query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error:NSError?)-> Void in
        if error == nil {
            self.postsArray = objects!
            self.postsTableView.reloadData()
            self.hideHUD()

        } else {
            self.simpleAlert("\(error!.localizedDescription)")
            self.hideHUD()
    }}
}

-

数据加载,应用程序没有崩溃,但错误让我抓狂。我还意识到有时滚动时会出现轻微的延迟,即使是一两秒。如果有人能提供帮助那就太好了,谢谢。

根据我们的讨论,您可以使用给定的方法更改您的方法:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! PostCell

    // Resize quote label
    cell.quoteView.frame = CGRectMake(30, 30, view.frame.size.width - 30*2, view.frame.size.width - 30*2)


    let postRecord = postsArray[indexPath.row]

    // Get User Pointer
    let userPointer = postRecord[POSTS_USER_POINTER] as! PFUser

    userPointer.fetchIfNeededInBackgroundWithBlock { (result, error) -> Void in
        cell.avatarImage.image = UIImage(named: "logo")
        let imageFile = userPointer[USER_AVATAR] as? PFFile
        imageFile?.getDataInBackgroundWithBlock({ (imageData, error) -> Void in
            if error == nil {
                if let imageData = imageData {
                    cell.avatarImage.image = UIImage(data:imageData)
                }}})
        cell.avatarImage.layer.cornerRadius = cell.avatarImage.bounds.size.width/2


        cell.usernameLabel.text = "\(userPointer[USER_FULLNAME]!)"


        cell.quoteLabel.text = "\(postRecord[POSTS_QUOTE]!)"
        let quoteColor = postRecord[POSTS_COLOR] as! Int
        cell.backgroundColor = colors[quoteColor]
        cell.quoteView.backgroundColor = colors[quoteColor]
    }


    // Assign tags to buttons in the cell
    cell.likeOutlet.tag = indexPath.row
    cell.reportOutlet.tag = indexPath.row
    cell.shareOutlet.tag = indexPath.row
    cell.avatarOutlet.tag = indexPath.row
    cell.commentOutlet.tag = indexPath.row

    return cell
    }