NavigationController的UIToolBar中的BarButtonim在ios7中不工作

NavigationController的UIToolBar中的BarButtonim在ios7中不工作,ios7,uinavigationcontroller,uibarbuttonitem,uitoolbar,toolbaritems,Ios7,Uinavigationcontroller,Uibarbuttonitem,Uitoolbar,Toolbaritems,我正在尝试在NavigationController的UIToolBar中添加BarButton。我在下面的代码中找到了堆栈溢出。但它在ios7中不起作用。如果有任何改变,为什么它在工具栏上什么也不显示 [self.navigationController setToolbarHidden:NO]; UIBarButtonItem *buttonItem = [[ UIBarButtonItem alloc ] initWithTitle: @"Select All"

我正在尝试在NavigationController的UIToolBar中添加BarButton。我在下面的代码中找到了堆栈溢出。但它在ios7中不起作用。如果有任何改变,为什么它在工具栏上什么也不显示

 [self.navigationController setToolbarHidden:NO];


 UIBarButtonItem *buttonItem = [[ UIBarButtonItem alloc ] initWithTitle: @"Select All"
                                            style: UIBarButtonItemStyleBordered
                                           target: self
                                           action: @selector(selectAll:) ];
  UIBarButtonItem *buttonNext = [[UIBarButtonItem alloc]initWithTitle:@"Next"     style:UIBarButtonItemStyleBordered target:self action:@selector(goNext:)];
   self.toolbarItems = [ NSArray arrayWithObjects: buttonItem, buttonNext, nil ];
//分配工具栏 UIToolbar*toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake0416320,44]; //创建酒吧基站 UIBarButtonItem*back=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selectorBack]; //设置间距 UIBarButtonItem*flexibleSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace目标:自我操作:nil]; UIBarButtonItem*forward=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward目标:自我操作:@selectorForward]; //将BTN添加到该栏 [工具栏设置项:[NSMutableArray arrayWithObjects:back、flexibleSpace、forward、nil]; //将工具栏添加到视图中 [self.view addSubview:工具栏];
我发现了问题。以上代码是正确的。工具栏中没有显示按钮的原因。我在班上也有这个功能。这是一个空函数。因此,它将覆盖默认的self.toolbarItems=[NSArray arrayWithObjects:buttonItem、buttonNext、nil]; 删除以下代码后。它现在工作得很好

 - (void)setToolbarItems:(NSArray *)toolbarItems animated:(BOOL)animated
 { 

 }

下次请正确设置代码格式,并尝试为答案添加一些解释。您需要将其添加到视图中。[self.view addSubview:self.toolbarItems]无需将此添加到视图中。因为这是导航控制器的默认属性。我们只需要将ToolBarHidden属性设置为“否”。我的代码正在运行。通过删除我的视图控制器中的函数。覆盖self.toolbarItems=[NSArray arrayWithObjects:buttonItem、buttonNext、nil];上面的代码在ios7中工作。这是我的错误。没问题,没问题。酷,它起作用了