diff options
Diffstat (limited to '')
-rw-r--r-- | foray/Base.lproj/Main.storyboard | 3 | ||||
-rw-r--r-- | foray/ForayTableViewController.swift | 18 |
2 files changed, 19 insertions, 2 deletions
diff --git a/foray/Base.lproj/Main.storyboard b/foray/Base.lproj/Main.storyboard index 17cfb05..b6b3f86 100644 --- a/foray/Base.lproj/Main.storyboard +++ b/foray/Base.lproj/Main.storyboard @@ -122,6 +122,9 @@ </connections> </tableView> <navigationItem key="navigationItem" title="Foray" id="UHk-DR-0EX"/> + <refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="SfP-IV-1Ks"> + <autoresizingMask key="autoresizingMask"/> + </refreshControl> </tableViewController> <placeholder placeholderIdentifier="IBFirstResponder" id="pPD-Wc-Rc9" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> </objects> diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift index 67f0bc5..0643051 100644 --- a/foray/ForayTableViewController.swift +++ b/foray/ForayTableViewController.swift @@ -64,6 +64,20 @@ class ForayTableViewController: UITableViewController { alert.view.addSubview(loadingIndicator) present(alert, animated: true, completion: nil) + reloadApiData() + + dismiss(animated: false, completion: nil) + + // Not 100% sure what this does (the for: bit) + self.refreshControl?.addTarget(self, action: #selector(doRefresh), for: UIControl.Event.valueChanged) + } + + // Not sure why need @objc. Is it due to class private/public? + @objc func doRefresh(sender: AnyObject) { + reloadApiData() + } + + func reloadApiData() { loadApiData(onComplete: { (apiItems) in self.items = apiItems @@ -77,9 +91,8 @@ class ForayTableViewController: UITableViewController { self.sections.sort { (lhs, rhs) in lhs.year < rhs.year } self.tableView.reloadData() + self.refreshControl?.endRefreshing() }) - - dismiss(animated: false, completion: nil) } func loadApiData(onComplete: @escaping ([MyItem]) -> ()) { @@ -97,6 +110,7 @@ class ForayTableViewController: UITableViewController { var request = URLRequest(url: URL(string: "https://.../dummy.json")!) let authData = ("..:..").data(using: .utf8)!.base64EncodedString() request.addValue("Basic \(authData)", forHTTPHeaderField: "Authorization") + request.cachePolicy = .reloadRevalidatingCacheData // Needed otherwise default caching policy seems not to check properly URLSession.shared.dataTask(with: request, completionHandler: { data, response, error -> Void in print("finished getting data") |