1

I have ViewController in which is WebView (loading web site inside) and I want on start loading to show UIActivityIndicator left in navigation controller and when loading is done remove it.

I have ViewController with embed navigation controller and I've tryed to put over IB UIIndicator but with no success, it's put in content part so pls tell me how programmatically put indicator in navigation bar left side.

Thank's for help

2 Answers 2

3

You won't be able to put an activity indicator in the nav bar using only storyboards, unfortunately.

Create an instance variable for the activity indicator:

@implementation
{
    UIActivityIndicatorView *activityIndicator;
}
...

In your viewDidLoad method, instantiate it and add it to the navigation bar:

activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];

The property hidesWhenStopped is YES by default, so it will hide when it's not animating automatically. All you have to do is call startAnimating and stopAnimating when you want it to be visible or hidden, respectively.

Sign up to request clarification or add additional context in comments.

2 Comments

I've created SingleViewController, add for ViewController "Emded in Navigation" and put your code + startAnimating in viewDidLoad but it is not showing up.
Yup, sorry, my fault. There was a small problem with the code. I've editing it and tested it in a fresh project and it works now.
0

Try this:

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
self.navigationController.navigationItem.leftBarButtonItem = button;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.