尝试以编程方式创建 rightBarButtonItem
这似乎不起作用。我做错了什么?
-(void)awakeFromNib{
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
NSLog(@"awaked");
[rightBarButtonItem release];
}
This doesn't seem to be working. What am i doing wrong?
-(void)awakeFromNib{
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
NSLog(@"awaked");
[rightBarButtonItem release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的猜测是,您将 UIBarButtonItem 添加到了错误的对象!
您需要将其添加到 rootViewController (而不是像您可能所做的那样添加到
UINavigationController
)my guess is, that you add the
UIBarButtonItem
to the wrong object!you need to add it, to the rootViewController (instead to the
UINavigationController
, as you probably did)我通常会将此代码放在
viewDidLoad
方法中,而不是awakeFromNib
方法中;我不确定这是否是你的问题所在。 “不工作”是什么意思?I would normally put this code in the
viewDidLoad
method rather than theawakeFromNib
method; I'm not sure if that's where your problem lies. What does "not working" mean?试试这个:
Try this instead: