I have been fighting for a few hours with different type of code to add a custom item to my Navigation Bar. Unfortunately its failing, and theres no debugging error. Right now im only able to change the title of the bar.
The code is added in viewDidLoad method in the particular ViewController:
UIBarButtonItem *gotoNext = [[UIBarButtonItem alloc] initWithTitle:@"Goto next" style:UIBarButtonItemStylePlain target:self action:@selector(gotoNextAction)];
self.navigationItem.rightBarButtonItem = gotoNext;
I tried following code but unfortunately without any luck:
UIView* container = [[UIView alloc] init];
UIButton * button = [[UIButton alloc] init];
[button setTitle:@"Test" forState:UIControlStateNormal];
[container addSubview:button];
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
self.navigationItem.rightBarButtonItem = item;
For this you have to add custom view in Navigation bar item
For more detail refer below link
Adding bar button item in navigation bar
How to add several UIBarButtonItems to a NavigationBar?