2

我已经通过故事板界面创建了导航控制器,并且我在导航栏上以编程方式添加了 4 个按钮,但我不知道我应该如何证明它的合理性,请你帮助我!

这是图片:

截屏

这是我知道的按钮代码我使用了rightBarButtonItems但我不知道应该写什么!

 - (void)viewDidLoad
{
[super viewDidLoad];

  UIBarButtonItem *menuButton= [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleDone  
       target:self action:@selector(menu:)];

UIBarButtonItem *yearButton= [[UIBarButtonItem alloc] initWithTitle:@"Year" style:UIBarButtonItemStyleDone
target:self action:@selector(year:)];
 UIBarButtonItem *weekButton= [[UIBarButtonItem alloc] initWithTitle:@"Week" style:UIBarButtonItemStyleDone 
 target:self action:@selector(week:)];
 UIBarButtonItem *reportButton= [[UIBarButtonItem alloc] initWithTitle:@"Report" style:UIBarButtonItemStyleDone 
  target:self action:@selector(report:)];

NSArray *buttons = [NSArray arrayWithObjects:menuButton,yearButton,weekButton,reportButton,nil];
self.navigationItem.rightBarButtonItems = buttons;
}
4

1 回答 1

5

在每个按钮之间添加灵活的垫片:

UIBarButtonItem *flexibleSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
于 2012-07-18T12:41:54.053 回答