SWIFT: +[CATransaction synchronize] called within transaction while decoding HTML entities

人走茶凉 提交于 2020-01-02 07:15:15

问题


I am making an app that fetches JSON content of a blog. The titles of the blog articles are shown in tableView.

The titles fetched were HTML encoded. So I decoded them using this code

func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
    let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject

    var encodedString = object.valueForKey("title")!.description
    var encodedData = (encodedString as NSString).dataUsingEncoding(NSUTF8StringEncoding)
    var attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType]
    var attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)

    var decodedString = attributedString.string
    cell.textLabel?.text = decodedString

    // cell.detailTextLabel?.text = object.valueForKey("publishedDate")!.description
}

I could accomplish the decoding and the titles are displayed in the simulator perfectly. But the console shows this error ThisIsMe[6837:2029906] +[CATransaction synchronize] called within transaction 4 times. There is no other error in the code and al other functions work well.

pls help


回答1:


This problem occurred during decoding HTML entities, so i looked for another way to decode and used the following code:

 func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
                let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject


      let eTitle:NSString = object.valueForKey("title")!.description
      let deTitle  = eTitle.stringByDecodingHTMLEntities()
      cell.textLabel?.text = deTitle
}

Earlier, the stringByDecodingHTMLEntities() was missing. So I had taken this approach.

Note: To Get stringByDecodingHTMLEntities() we need to import NSString+HTML.h, from here NSString category for HTML



来源:https://stackoverflow.com/questions/28457998/swift-catransaction-synchronize-called-within-transaction-while-decoding-htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!