0

I am trying to show an activity indicator when a user taps a certain TabBar item. My problem, I think, lies in the fact that the UI Main thread is frozen.

When a user taps the TabBar I prepare a big data list that takes about six seconds. I get the activity to show everywhere but when they tap the TabBar.

It seems as though the indicator is "running" because when the segued uitableviewcontroller shows, it is showing the indicator. But this is too late and dispatch doesn't seem to do anything either.

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    if let visibleViewCtrl = UIApplication.shared.keyWindow?.visibleViewController {
        // do whatever you want with your `visibleViewCtrl`
        print (String.init(describing: visibleViewCtrl.classForCoder))
        DispatchQueue.main.async{

            let aprogressView = ProgressView(Message: "Filtering...",
                                        Theme:.Dark,
                                        IsModal:true);

            visibleViewCtrl.view.addSubview(aprogressView)
            aprogressView.show()
        }
    }
    return true
}

OK, So the problem is that it is going to a tableview controller, which tries to get rows in section almost immediatetly, which then first the fetchrequest which blocks everything as it is on the main thread.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jimijon
  • 2,046
  • 1
  • 20
  • 39

1 Answers1

0

SOLVED:

Added a boolean:

 var loadData = false

 override func viewDidAppear(_ animated: Bool) {
        loadData = true
        self.tableView.reloadData()
 }

Then the delegates:

func sectionIndexTitles(for tableView: UITableView) -> [String]? {
    if loadData == false {
        return nil
    }
    return  searchFetchedResultsController.sectionIndexTitles

}



func numberOfSections(in tableView: UITableView) -> Int {
    if loadData == false {
        return 0
    }

Now it will transition to the new controller immediately and thus I can now show feedback from viewWillAppear :

appDelegate.progressView = ProgressView(Message: "Filtering Brands", Theme:.Dark, IsModal:true);
    appDelegate.progressView!.show()

This will NOT work with programatical display

    self.navigationController?.pushViewController(vc, animated: false)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jimijon
  • 2,046
  • 1
  • 20
  • 39