Can not show the rightbar button - ios sdk

897 views Asked by At

I had add image at my navigation bar and need to add the right bar refresh button. But the right bar button can not show at the navigation after add. Why?

Here the code add image at navigation bar:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"topbar.png"] forBarMetrics:UIBarMetricsDefault];

Here the add right bar button at viewDidLoad:

UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh: )];

NSArray *actionButtonItems = @[refreshItem];
self.navigationController.navigationItem.rightBarButtonItems = actionButtonItems;
4

There are 4 answers

0
iPatel On

Try with following code

UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh: )];      
self.navigationItem.rightBarButtonItem = refreshItem;
0
Nirmalsinh Rathod On
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Refresh"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(rightButtoneClicked:)];
self.navigationItem.rightBarButtonItem = rightButton;

Right this code in viewDidLoad and you get the refresh button on right side.

0
Bhumeshwer katre On

Replace this

self.navigationController.navigationItem.rightBarButtonItems = actionButtonItems;

With:

self.navigationItem.rightBarButtonItems = actionButtonItems;
0
Mavericks On

You should not add to self.navigationcontroller.

Do something like this will resolve your problem.

  self.navigationItem.rightBarButtonItem  = refreshItem;