本文介绍了如何在代码中的 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;

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.

解决方案

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:

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

这篇关于如何在代码中的 UIToolBar 中添加 UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 13:35