// initing the loading view
CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[loading startAnimating];
loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);

// initing the bar button
UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:loading];

loadingView.target = self;

self.navigationItem.rightBarButtonItem = loadingView;