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
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.