Search code examples
iosobjective-cuinavigationcontrolleruinavigationbaruinavigationitem

Not able to add UIBarButton to navigation bar


I have downloaded this source code here and its working fine.

But I need to add a button on SBInstagramCollectionViewController navigationbar ,I tried following code and am not able to see that button there (Looks like somethng wrong).

//Add button to NavigationController
UIBarButtonItem *backButton = 
 [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@“back”, @"")
                                  style:UIBarButtonItemStylePlain 
                                 target:self 
                                 action:@selector(goBack)];

self.navigationItem.leftBarButtonItem = backButton;

Please help me....


Solution

  • Try adding your code for UIBarButtonItem in the viewDidLoad method of SBInstagramCollectionViewController.m class in the project

    -(void)viewDidLoad {
    
             [super viewDidLoad];
    
             //Other code
    
             //Add button to NavigationController
             UIBarButtonItem *backButton =
             [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain  
                                             target:self action:@selector(goBack)];
    
             self.navigationItem.leftBarButtonItem = backButton;
    }