我正在尝试实现工具栏按钮
在这种情况下,我的视图中有一个编辑按钮。
我在检查器中选择工具栏,然后添加一个带有故事板的按钮。
我在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];
}
答案 0 :(得分: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];
}