以编程方式添加导航栏按钮...但它不会显示!
我正在以编程方式添加一个 UIBarButtonItem
,但是该死的东西不会将自己添加到导航栏(已在 IB 中添加)。这是我用来添加它的代码:
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
self.navigationItem.rightBarButtonItem = shareButton;
在我的 viewDidLoad
中。由于我是以编程方式执行此操作,这是否意味着导航栏也必须以编程方式完成?我想不出任何其他原因来解释为什么它不会添加自身。
I'm adding a UIBarButtonItem
programatically, however the damned thing won't add itself to the navigation bar (which was added in IB). Here's the code I'm using to add it:
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
self.navigationItem.rightBarButtonItem = shareButton;
in my viewDidLoad
. Since I'm doing that programatically, does that mean that the nav bar has to be done programatically as well? I can't think of any other reason as to why it won't add itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个愚蠢的建议,但是您确定您的 self.navigationItem IBOutlet 已在 NIB 中设置吗?即,也许您在 NIB 中设置一切正常并且看起来正确,但如果插座未连接,您将无法使用它。
It may be a silly suggestion, but are you sure that your self.navigationItem IBOutlet is set in the NIB? i.e. maybe you are setting everything up OK in your NIB and it looks right, but if the outlet isn't connected you won't be able to use it.