I have these two methods:
func showSpinner()
{
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .White)
spinner.startAnimating()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: spinner)
self.navigationItem.hidesBackButton = true
}
func hideSpinner()
{
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = false
}
In viewDidLoad
I call showSpinner
and then after data loaded I call hideSpinner
. But backButton often jumping on hideSpinner
. How to fix it?
You can use delay to show the back button after removing the spinner. Like 0.2 seconds or as per the requirement
func hideSpinner()
{
self.navigationItem.leftBarButtonItem = nil
dispatch_after(1, dispatch_get_main_queue()) { () -> Void in
self.navigationItem.hidesBackButton = false
};
}