Adding a navigation bar button - ios

I am trying to add a button to the navigation bar in the view, but it is not showing up.
I have:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"audio-controls"] style:UIBarButtonItemStylePlain target:self action:#selector(toggleAudioPlaybackView:)];
in a viewDidLoad.
EDIT: It is also important to note that I am also using storyboard.
EDIT: I think there is an issue with self.navigationItem... it's not nil but no changes are being made to it.

Related

iOS 9 back barButtonItem not showing on navigation controller

Similar to the issue described here, with the exception that my TabBar is actually showing the BackButton on my NavigationBar is not. In the question I provided a link to the answer that solved the problem was that there was a NavigationController within a NavigationController, I do not have that so this is a different issue.
The basic flow of my storyboard is Login (UIView) - TabBar (UITabBarController) - NavigationController (UINavigationController) - Actual visible screen (UITableViewController) - New TableView where the issue occurs (UITableViewController).
On the new actual visible screen or the TableView the NavigationBar at the top shows just fine and I can click in the general area that the BackBarButton should be and it will go back, but no BackBarButton item is visible.
I tried changing the color, allocating it in the previous ViewController, making sure it was visible, etc. And none of them have shown the Back Button. It seems to be there but it is not shown.
Any ideas? From the other question that is similar to my issue this seems to be a iOS 9 specific thing.
EDIT from looking at the Debug View Hierarchy I can tell that the back button is in fact there but it just has no label or back arrow on it. How can I make the back label visible?
EDIT 2
Here is the viewDidLoad method of the view controller where the back button should appear.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem.backBarButtonItem setTintColor:[UIColor whiteColor]];
// Other unimportant stuff
}
The way I am segueing to this view controller is through the storyboard with a Push segue. Code is below.
- (void)segueToUser: (UIButton*)button {
long row = button.tag;
PFObject *PFQuote = [_recent quoteAtIndex:(row-1)/2];
PFUser *u = [PFQuote objectForKey:#"creator"];
_send = u;
[self performSegueWithIdentifier:#"showUser" sender:self];
}
Here is my prepareForSegue in the same file as the segueToUser
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showUser"]) {
BRETTFUserTableViewController *bfutvc = [segue destinationViewController];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
bfutvc.us = _send;
}
}
Here is a picture of a section of my storyboard.
The first view is a tabView
The second view is a navView
The third view is a tableView
The fourth view is a tableView
Since no one has seemed to have found a solution I will provide additional information. From my digging deeper into the Debug View Hierarchy I have found some more information regarding the backButton. I can see that the back arrow is intact there and there is a NSString next to it that seems to be nil, I do not know why it is nil but that is what I found. Here are additional pictures of what I have found.
In your
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
you have Write a code line
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
In Above line you have set title " " Empty String.
Instead of empty string use the title which you want to show on back-button item. fr ex:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
Check it might that help.
Adding a image of storyboard, how i have embedded the view controller in navigation controller.
or in case if you have put navigation appearance code anywhere in your app then also post that code.
In your viewDidLoad and prepareForSegue methods you have this :
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
Which replace the default back button of the navigation controller by a button without a label.
You should simply remove these 2 lines to have the default back button.
I have finally solved the issue. To accomplish this I had to go into the navigation bar for the first tableViewController and set the Back Button title to Back and then set the tint color (as it defaulted to clear) and now it works.

Xcode Master Detail Application back button properties

How do I add properties for the "back button" in the navigation bar? The button links from detail view and back to the master view. I can't find any code for the back button, and the button is hidden in storyboard view.
This back button is added automatically by the UINavigationController in iOS, you can customize some things like the name, e.g. if you want to change the title or remove it totally while keeping the icon, you can use the below code:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Custom Title"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
Leave the title #"" if you want no text; also you can customize the behavior of the button by adding your own method like this:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Custom Title"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(backButtonEvent)];
- (void)backButtonEvent {
// Your code here
}
Be careful, this should be added to viewDidLoad in the first controller, not the second one.

Add more then one button in top navigation bar in iOS

I am currently developing a chat application and within this I have to add more then 1 left bar button in navigation bar. I am developing it using xib file.
I already added left and right bar button now I want to add 2 more in the left side of navigation bar.
UINavigationItem Class Reference having property of leftBarButtonItems and rightBarButtonItems so you can add multiple UIBarButtonItem in your navigation control using following example code:
UIBarButtonItem *FirstButton = [[UIBarButtonItem alloc]
initWithTitle:#"First"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(AcionFirst:)];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc]
initWithTitle:#"Second"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(AcionSecond:)];
self.navigationItem.leftBarButtonItems= [NSArray arrayWithObjects:FirstButton,secondButton,nil];
-(void)AcionFirst:(id)sender
{
//do something for first bar button
}
-(void)AcionSecond:(id)sender
{
//do something for second bar button
}

UIBarButton added to UINavigationItem not showing up

I am trying to add a bar button to my iOS app and can't get it to show up. I can see the bar in the Navigation Item's view hierarchy by setting a breakpoint. If it helps, I chose 'Embed Navigation Controller'. Any idea what's going on?
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(choosePreferredTerm:)];
[self.navItem setRightBarButtonItem:item animated:YES];
Here is the connection in IB
This is what the embedded Navigation Controller looks like:
This is what it looks like on the sim:
Try this rather than using custom outlet "navItem" also insure your application has a navigation controller in place
self.navigationItem.rightBarButtonItem = barButton;

UIBarButtonItem not appearing

My app layout is as follows -
the rootViewController is a tabViewController with 3 tabs each having a UINavigationController as their rootViewController. Within one of these tabs I am pushing upon cell selection to another tabController which now has two tabs. What I am trying to do is set the rightBarButtonItem on each of these two tab's viewControllers... in the viewDidLoad method of both of these I am doing:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(selectionChanged:)];
however this is doing absolutely nothing! I thought from the apple documentations that you could set the navigationItem's rightBarButtonItem from anywhere within your navigation controllers view hierarchy but that doesn't seem to be the case here. Any idea what - if anything - I am doing wrong?
The solution to this is to instead of simply setting the rightBarButtonItem on self.navigationItem we need to set it on the parent tabBarController like so :
self.tabBarController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(selectionChanged:)];

Resources