Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在代码中的UIToolBar中添加UIBarButtonim_Objective C_Xcode_Ios_Uibarbuttonitem - Fatal编程技术网

Objective c 如何在代码中的UIToolBar中添加UIBarButtonim

Objective c 如何在代码中的UIToolBar中添加UIBarButtonim,objective-c,xcode,ios,uibarbuttonitem,Objective C,Xcode,Ios,Uibarbuttonitem,我有标准的犹太教 UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)]; UIBarButtonItem*共享=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemActi

我有标准的犹太教

UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)]; UIBarButtonItem*共享=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction目标:自我操作:@selector(共享:)]; 如何将她添加到UIToolBar?我试过了

self.toolbarItems = [NSArray arrayWithObject:share]; self.toolbarItems=[NSArray arrayWithObject:share];
但它不起作用。需要您的帮助。

确保工具栏未被隐藏;您可以尝试将以下内容添加到视图控制器的
视图将显示:动画:
方法:

[self.navigationController setToolbarHidden:NO animated:YES];

[工具栏设置项:[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];

很抱歉这意味着工具栏显示时没有任何按钮。现在,尝试使用wayFind解决方案[self-setToolbarItems:[NSArray arrayWithObject:share]];