objective-c - 如何在代码中的 UIToolBar 中添加 UIBarButtonItem

标签 objective-c xcode ios uibarbuttonitem

我有标准的 UIBarButtonItem

UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)];

如何将她添加到UIToolBar?我试过了

    self.toolbarItems = [NSArray arrayWithObject:share];

但它不起作用。需要你的帮助。

最佳答案

你能比“它不起作用”更具体吗?

如果您尝试向已有项目的工具栏添加项目,则需要修改项目数组:

NSMutableArray *newItems = [self.toolbarItems mutableCopy];
[newItems addObject:share];
self.toolbarItems = newItems;

关于objective-c - 如何在代码中的 UIToolBar 中添加 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383906/

相关文章:

ios - JSONModel:填充泛型类型的 NSArray

ios - 推送到另一个 ViewController 时隐藏 NavigationBar

objective-c - Xcode : How to add Protocol to a socket Connection and send JSON data

objective-c - 如何编写在 Objective-C 中调用 `super` 实现的 c 函数?

ios - 在 iOS 中使用公钥验证数字签名

iphone - block 内的弱引用

ios - UIButton NSAttributedString 不会更新字体颜色

swift - 即使应用程序关闭,每月编译用户数据的最佳方法

关闭优化时 C 库崩溃

ios - `React/RCTBridgeModule.h` 找不到文件