gpt4 book ai didi

ios - warnBlockingOperationOnMainThread 错误

转载 作者:行者123 更新时间:2023-11-29 01:44:54 24 4
gpt4 key购买 nike

我正在使用 parse 创建一个应用程序,我收到一条警告说 “正在主线程上执行长时间运行的 Parse 操作。中断 warnParseOperationOnMainThread() 进行调试。” 所以我有在 warnBlockingOperationOnMainThread 中放置一个断点。应用程序在断点处停止并指出 item.fetchIfNeeded。为什么会这样?我没有发现我的代码有任何问题。任何帮助表示赞赏。谢谢!

  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("loveView", forIndexPath: indexPath) as! LoveCollectionViewCell
let item = self.votes[indexPath.row]


let gesture = UITapGestureRecognizer(target: self, action: Selector("onDoubleTap:"))
gesture.numberOfTapsRequired = 2
cell.addGestureRecognizer(gesture)


// Display "initial" flag image
var initialThumbnail = UIImage(named: "question")
cell.postsImageView.image = initialThumbnail

// Display the country name
if let user = item["uploader"] as? PFUser{
item.fetchIfNeeded()
cell.userName!.text = user.username


var profileImgFile = user["profilePicture"] as! PFFile
cell.profileImageView.file = profileImgFile
cell.profileImageView.loadInBackground { image, error in
if error == nil {
cell.profileImageView.image = image
}
}

var sexInt = user["sex"] as? Int
var sex: NSString!
if sexInt == 0 {
sex = "M"
}else if sexInt == 1{
sex = "F"
}else{
sex = " "
}

var height = user["height"] as? Int
if height == nil{
cell.heightSexLabel.text = " "
}else{
var nonOpHeight = height as Int!
cell.heightSexLabel.text = "\(sex) \(nonOpHeight)cm"
}


}

if let votesValue = item["votes"] as? Int
{
cell.votesLabel?.text = "\(votesValue)"
}

// Fetch final flag image - if it exists
if let value = item["imageFile"] as? PFFile {
println("Value \(value)")
cell.postsImageView.file = value
cell.postsImageView.loadInBackground({ (image: UIImage?, error: NSError?) -> Void in
if error != nil {
cell.postsImageView.image = image
}
})
}

//Adjusting the position of heart image
cell.votesLabel!.sizeToFit()
cell.votesLabel!.center = CGPointMake(cell.bottomBlurView.center.x - (cell.heartImage.frame.width / 2)-1.5, cell.bottomBlurView.frame.size.height / 2)
cell.heartImage.frame.origin.x = cell.votesLabel!.frame.origin.x + cell.votesLabel!.frame.width + 1.5



return cell
}

最佳答案

因为 fetcIfneeded 方法会在主线程执行,所以使用 fetchIfNeededInBackgroundWithBlock 方法代替。在 block 内部检查 success = true 然后获取文件。

关于ios - warnBlockingOperationOnMainThread 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com