简体   繁体   中英

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....

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM