Follow @ogre_codes to get notified when new articles are posted to this site.
Jun 15, 2017 at 10:27 AM
So much going on right now in my life it’s been incredibly hard to find a peaceful place and state of mind where I can be heads down on code. The past week I’ve finally been able to get some time and I’ve made a ton of progress on my blogging app.
I switched the app to use UIDocument and FileWrappers so I could support images and other attachments and possibly iCloud syncronization. Currently images can be selected and saved as part of the document, to add them to the documents, I have to add support to the templates, image scaling, and uploading which I’ll be working on over the next few days.
In addition to switching the document model, I changes the table-views to use iOS’s built in table row update support. Previously I was reloading the entire table every time I updated a row which was quite crude and visually a bit gross. The new method checks if the row has moved and if needed relocates it in the table.
func updateListEntry(_ entry: BlogEntry) {
// Refresh the view and move the row if needed
guard let oldRow = entryList.entries.index(of:entry) else {
fatalError(“Entry is not in the table”)
}
entryList.resequence()
let oldIndex = IndexPath(row:oldRow, section: 0)
entryTableView.reloadRows(at: [oldIndex], with: .automatic)
guard let newRow = entryList.entries.index(of:entry) else {
fatalError(“Entry removed from the table”)
}
if oldRow != newRow {
let newIndex = IndexPath(row:newRow, section: 0)
entryTableView.moveRow(at: oldIndex, to: newIndex)
}
}