2016-06-01 5 views
1

이 질문을 여러 번 게시했지만 해결 방법을 찾지 못했습니다.장기 실행 작업이 주 스레드에서 실행 중입니다.

경고 : 장기 실행 작업이 주 스레드에서 실행되고 내가 구문 분석을 사용하고 이 오류를 받기 SDK @ back4app.com

개최했다. 디버그하려면 warnBlockingOperationOnMainThread()를 중단하십시오.

데이터로드 및 응용 프로그램이 중단되지 않고 오류가 날 미치게됩니다 -

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() 
    }} 
} 

: 내 home.swift 파일에서

코드입니다. 나는 또한 두 번째 또는 두 번째 때로는 때때로 스크롤 할 때 약간의 지연이 있음을 깨달았다. 누구든지 도움이된다면 도움이 될 것입니다.

+1

당신은 메인 큐 외부 로딩을 할 필요가 있으며 메인 큐에서 UI를 업데이트 할 때. – DMH

+0

무엇이 당신의 질문입니까? 백그라운드 스레드에서 작업을 실행하는 방법을 알고 싶습니까? – Feroz

+0

@feroz 미안하지만, 제 질문은 실제로 제 오류를 막을 수있는 방법입니다. PFObject를 AnyObject로 바꾸려면 여기를 읽으십시오. 작동하지 않습니다. 그래서 어떻게 백그라운드 스레드에서 실행할 수 있습니까? ? 나는 이것을 시도 할 수있다. – OnlyDanWilliams

답변

1

우리의 논의에 따라 경찰은 주어진 방법으로 방법을 변경할 수 있습니다

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 
    } 
관련 문제