From 6235b4f7f8a172b0c8595527184a9e6c0c4cb79c Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 16 Mar 2022 10:21:08 +1100 Subject: Loading overlay on main screen I'm not 100% sure if this is the best way to do it, but it looks decent and it works. Resources: - https://stackoverflow.com/questions/27960556/loading-an-overlay-when-running-long-tasks-in-ios --- foray/ForayTableViewController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'foray') diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift index fd4854e..67f0bc5 100644 --- a/foray/ForayTableViewController.swift +++ b/foray/ForayTableViewController.swift @@ -55,6 +55,15 @@ class ForayTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() + // Not sure if this is the right way to go about this... + let alert = UIAlertController(title: nil, message: "Grabbing data...", preferredStyle: .alert) + let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50)) + loadingIndicator.hidesWhenStopped = true + loadingIndicator.style = UIActivityIndicatorView.Style.medium + loadingIndicator.startAnimating(); + alert.view.addSubview(loadingIndicator) + present(alert, animated: true, completion: nil) + loadApiData(onComplete: { (apiItems) in self.items = apiItems @@ -69,6 +78,8 @@ class ForayTableViewController: UITableViewController { self.tableView.reloadData() }) + + dismiss(animated: false, completion: nil) } func loadApiData(onComplete: @escaping ([MyItem]) -> ()) { -- cgit