如何在代码中添加UIToolBar中的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;
确保你已经编制了一个IBOutlet或添加工具栏的工具栏
IBOutlet UIToolbar *toolBar; UIBarButtonItem *infoButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"info" style:UIBarButtonItemStyleBordered target:self action:@selector(infoButtonClicked)]; toolBar.items = [NSArray arrayWithObjects:infoButtonItem, nil];
确保工具栏不隐藏; 你可以尝试添加以下内容到你的视图控制器的viewWillAppear:animated:
method:
[self.navigationController setToolbarHidden:NO animated:YES];
[toolbar setItems:[NSArray arrayWithObject:share] animated:YES];
- TableViewSuite App的哪种types的项目
- 在检查其他方法问题之前应该调用SegueWithIdentifier
- 从XCAsset目录中获取数据
- 为什么NSUserDefaults无法保存NSMutableDictionary?
- 如果显示WKAlert,Watch App会在停用时终止
- 方法presentViewController在更新后不能在iOS 8.3上工作
- 多点触控touchEvents不会触发,因为它们应该在Safari Mobile上
- Storyboard Global Tint UITabBar Tint在IOS 7.1中发生了变化
- iOS6没有libxml2.2.7.3.dylib.are有替代品吗?