【问题标题】:Not able to add UIBarButton to navigation bar无法将 UIBarButton 添加到导航栏
【发布时间】:2014-09-01 06:35:56
【问题描述】:

我已经下载了这个源代码here 并且它工作正常。

但我需要在SBInstagramCollectionViewController 上添加一个按钮 导航栏,我尝试了以下代码,但在那里看不到那个按钮(看起来有问题)。

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

self.navigationItem.leftBarButtonItem = backButton;

请帮帮我....

【问题讨论】:

  • 检查您在可本地化中是否有 @“back” 的值。或者试试initWithTitle:@"back"
  • 试过都不起作用
  • 我在同一个示例中尝试了您的代码并且它可以正常工作。你能检查一下你的导航栏没有隐藏吗
  • 你能分享你的代码吗

标签: ios objective-c uinavigationcontroller uinavigationbar uinavigationitem


【解决方案1】:

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

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

【讨论】:

  • 当前代码是viewdidload本身请查看附件
  • 当前代码在 viewdidload 中,请查看附件截图
  • 我已经尝试在代码示例中使用 UIBarButtonItem ,并且工作正常。我只是从您提供的链接中下载了代码,并将代码添加到 SBInstagramCollectionViewController.m 类的 UIBarButtonItem 中。看看s11.postimg.org/u43e5wz43/…
猜你喜欢
  • 1970-01-01
  • 2010-12-05
  • 1970-01-01
  • 2017-03-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
相关资源
最近更新 更多