1

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?

enter image description here

ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
  • you can use this method `- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated;` to show the back button using animation – Vijay Masiwal May 18 '15 at 12:57
  • Already tried the same result. – ChikabuZ May 18 '15 at 13:00
  • 1
    Have you tried to show the back button with some delay like 0.2 or as per the requirement like this- `func hideSpinner() { self.navigationItem.leftBarButtonItem = nil dispatch_after(1, dispatch_get_main_queue()) { () -> Void in self.navigationItem.hidesBackButton = false }; }` – Vijay Masiwal May 18 '15 at 13:01
  • Thank you it's works, you can write is as answer, but I don't understand why it happens? – ChikabuZ May 18 '15 at 13:09
  • Bcos you are trying to do two tasks remove spinner and show back button at the same time. – Vijay Masiwal May 18 '15 at 13:13

1 Answers1

4

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
    };
}
Vijay Masiwal
  • 1,153
  • 8
  • 12