I have This Code for Read UITable
var documents = PDFDocument
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! BookshelfCell
let document = documents[indexPath.row]
if let documentAttributes = document.documentAttributes {
if let title = documentAttributes["Title"] as? String {
cell.title = title
}
if let author = documentAttributes["Author"] as? String {
cell.author = author
}
if document.pageCount > 0 {
if let page = document.page(at: 0), let key = document.documentURL as NSURL? {
cell.url = key
if let thumbnail = thumbnailCache.object(forKey: key) {
cell.thumbnail = thumbnail
} else {
downloadQueue.async {
let thumbnail = page.thumbnail(of: CGSize(width: 40, height: 60), for: .cropBox)
self.thumbnailCache.setObject(thumbnail, forKey: key)
if cell.url == key {
DispatchQueue.main.async {
cell.thumbnail = thumbnail
}
}
}
}
}
}
}
return cell
}
I have Save the PDFs like this
private func refreshData() {
let fileManager = FileManager.default
let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let contents = try! fileManager.contentsOfDirectory(at: documentDirectory, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
documents = contents.flatMap { PDFDocument(url: $0) }
tableView.reloadData()
}
Now I want to Displaced the Pdf’s in Uitable
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let movedObject = self.documents[sourceIndexPath.row]
documents.remove(at: sourceIndexPath.row)
documents.insert(movedObject, at: destinationIndexPath.row)
refreshData()
}
But After the code goes to refreshData()
the Pdf Back to Previous mode (Previous Place)
Maybe I will Change the refreshData() Part and Save the Pdf Method Please Help me