views:

497

answers:

4

I am new to iphone development.I want to set an activity indicator in the navigation bar.I see my activity indicator below the navigation bar.My code is here

  -(IBAction) gomethod : (id) sender
{
 xxMapSubviewcontroller = [[XxMapSubviewcontroller alloc] init];
[self.navigationController pushViewController:xxMapSubviewcontroller animated:YES];

activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
[activityIndicator startAnimating];

[xxMapSubviewcontroller.view addSubview:activityIndicator];
 }

How can i set my activity indicator in the navigation bar? Please help me out.Thanks.

A: 

You are creating a new activity indicator view here, which is fine, but you are not referring to the activity indicator in the status bar.

To show the activity indicator in the status bar, simply call this:

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
Zoran Simic
I want to display the activity indicator in the navigation bar
Warrior
+4  A: 

I add the below piece of code in the view where i wanted the activity indicator in the navigation bar.

 activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[self navigationItem].rightBarButtonItem = barButton;
    [activityIndicator startAnimating];
Warrior
+1  A: 

I had a similar question with response here: http://stackoverflow.com/questions/2249363/iphone-programatically-change-navigation-bar-button-to-activity-indicator

I wanted to change the refresh button in the nav bar to the activity indicator and back again.

cagreen
Thanks , i will try that too....
Warrior
A: 

try . self.navigationItem.leftBarButtonItem.customView = your view

Robin