How to set the activity indicator in the navigation bar?

Warrior picture Warrior · Feb 18, 2010 · Viewed 30.6k times · Source

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.

Answer

Warrior picture Warrior · Feb 18, 2010

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

activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[self navigationItem].rightBarButtonItem = barButton;
[activityIndicator startAnimating];