如何在代码中的UIToolBar中添加UIBarButtonItem
我有标准 UIBarButtonItem
UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)];
如何将她添加到 UIToolBar?我已经尝试过
self.toolbarItems = [NSArray arrayWithObject:share];
但它不起作用。需要你的帮助。
I have standart UIBarButtonItem
UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)];
How to add her to UIToolBar? I've tried
self.toolbarItems = [NSArray arrayWithObject:share];
But it doesn't work. Need your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你能比“它不起作用”更具体吗?
如果您尝试将项目添加到已有项目的工具栏中,则需要修改项目数组:
Can you be more specific than "it doesn't work"?
If you're trying to add an item to a toolbar that already has items, you'll need to modify the array of items:
确保您已将工具栏制作为 IBOutlet 或以编程方式添加工具栏
Make sure you have make a toolbar either an IBOutlet or added toolbar programatically
确保工具栏没有隐藏;您可以尝试将以下内容添加到视图控制器的
viewWillAppear:animated:
方法中:Make sure the toolbar isn't hidden; you could try adding the following to your view controller's
viewWillAppear:animated:
method:[工具栏 setItems:[NSArray arrayWithObject:share] 动画:YES];
[toolbar setItems:[NSArray arrayWithObject:share] animated:YES];