Question

Hello all I am making an app that uses a tab bar controller with three tabs as well as a slide out navigation drawer. and my question is how do I put a bar button item in the top left hand corner. It doesn't show when I run my app but it shows in a regular view controller. here is the code I have.

#import "FirstViewController.h"
#import "SWRevealViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UITabBar appearance] setTintColor:[UIColor redColor]];


    [self.tabBarController setTitle:@"News"];

    // Change button color
    _sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.9f];

    // Set the side bar button action. When it's tapped, it'll show up the sidebar.
    _sidebarButton.target = self.revealViewController;
    _sidebarButton.action = @selector(revealToggle:);

    // Set the gesture
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

just so you can see what im on about (firstview)

Was it helpful?

Solution

Since you seem to be using storyboard, my recommendation is to find the Bar Button Item in the Object Library and drag it into the top left hand corner of your FirstViewController (and any other controller that you want the button in). This will replace the original back button created by the Navigation Controller with your own button. In the button's Attribute Inspector you can give it an image, and connect it to your code by control+dragging to your FirstViewController.h file.

OTHER TIPS

Assuming you have a @property for your button

self.navigationItem.leftBarButtonItem = self.sidebarButton;

Also, is this the best place to customize your TabBar?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top