无法将UIBarButton添加到导航栏

时间:2014-09-01 06:35:57

标签: ios objective-c uinavigationcontroller uinavigationbar uinavigationitem

我已下载此源代码here并且其工作正常。

但我需要在SBInstagramCollectionViewController上添加一个按钮  导航栏,我尝试了下面的代码,但我无法在那里看到那个按钮(看起来有点错误)。

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

self.navigationItem.leftBarButtonItem = backButton;

请帮助我....

1 个答案:

答案 0 :(得分:0)

尝试在项目中UIBarButtonItem类的viewDidLoad方法中添加SBInstagramCollectionViewController.m的代码

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