0

我正在尝试实现一个工具栏按钮。
在这种情况下,我认为是一个编辑按钮。
我在检查器中选择工具栏,然后添加一个带有情节提要的按钮。
我在 viewdidload 中写了这个方法,但是出了点问题。该按钮未显示在工具栏中。

有人可以帮我让它工作吗?

 - (void)viewDidLoad
{
     [super viewDidLoad];

     UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Birds"
                                                                    style:UIBarButtonItemStyleBordered 
                                                                   target:self 
                                                                   action:@selector(goToBirdsView:)];

     NSArray *toolbarItems = [NSArray arrayWithObject:editButton];

     self.navigationController.toolbarHidden = NO;
}

-(IBAction)goToBirdsView:(UIButton *)sender 
{
     [self performSegueWithIdentifier:segueToBirdsList sender:self];
}
4

1 回答 1

0
- (void)viewDidLoad
{
     toolBar = [[UIToolBar alloc]initWithFrame:(As_U_Need)];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        [barItems addObject:flexSpace];

        UIBarButtonItem * editButton= [[UIBarButtonItem alloc] initWithTitle:@"Birds" style:UIBarButtonItemStyleBordered target:self action:@selector(goToBirdsView:)];
    [barItems addObject: editButton];

    [toolBar setItems:barItems animated:YES];
    [self.view addSubView:toolBar];

}

-(IBAction)goToBirdsView:(UIButton *)sender 
{
           [self performSegueWithIdentifier:segueToBirdsList sender:self];
}
于 2013-02-11T10:50:24.270 回答