Add some form of image for when no configurations are available.

This commit is contained in:
Jeroen Leenarts 2018-10-02 21:33:24 +02:00
parent d12542a0c2
commit 03c257cfcc
3 changed files with 35 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Arrow.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"preserves-vector-representation" : true
}
}

View File

@ -188,6 +188,7 @@ extension TunnelsTableViewController: Identifyable {}
class TunnelFetchedResultsControllerDelegate: NSObject, FetchedResultsControllerDelegate {
private weak var tableView: UITableView?
private var arrowImage: UIImageView?
// MARK: - Lifecycle
init(tableView: UITableView) {
@ -196,6 +197,7 @@ class TunnelFetchedResultsControllerDelegate: NSObject, FetchedResultsController
func fetchedResultsControllerDidPerformFetch(_ controller: FetchedResultsController<Tunnel>) {
tableView?.reloadData()
updateEmptyIndicator(controller)
}
func fetchedResultsControllerWillChangeContent(_ controller: FetchedResultsController<Tunnel>) {
@ -204,6 +206,7 @@ class TunnelFetchedResultsControllerDelegate: NSObject, FetchedResultsController
func fetchedResultsControllerDidChangeContent(_ controller: FetchedResultsController<Tunnel>) {
tableView?.endUpdates()
updateEmptyIndicator(controller)
}
func fetchedResultsController(_ controller: FetchedResultsController<Tunnel>, didChangeObject change: FetchedResultsObjectChange<Tunnel>) {
@ -233,6 +236,23 @@ class TunnelFetchedResultsControllerDelegate: NSObject, FetchedResultsController
tableView.deleteSections(IndexSet(integer: index), with: .automatic)
}
}
private func updateEmptyIndicator(_ controller: FetchedResultsController<Tunnel>) {
guard let tableView = tableView else { return }
if controller.count > 0 {
tableView.backgroundView = nil
arrowImage = nil
} else {
if arrowImage == nil {
let imageView = UIImageView(image: UIImage(named: "Arrow"))
imageView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
imageView.frame = tableView.bounds
imageView.contentMode = .bottomRight
tableView.backgroundView = imageView
arrowImage = imageView
}
}
}
}
protocol TunnelTableViewCellDelegate: class {