Objective c 如何在代码中的UIToolBar中添加UIBarButtonim
我有标准的犹太教 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];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
但它不起作用。需要您的帮助。确保工具栏未被隐藏;您可以尝试将以下内容添加到视图控制器的
视图将显示:动画:
方法:
[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]];