ios – UIToolbar不显示UIBarButtonItem

我正在使用一个故事板,我有一个拆分视图,主人是一个UITableViewController.像iPad Mail应用程序一样,我想显示一个UIToolbar.

我无法通过故事板添加工具栏,但我设法以编程方式添加.我也可以在工具栏中添加一个UILabel,但是我找不到添加一个刷新按钮或者任何一种UIBarButtonItem的方法.

任何想法?

- (void)viewDidLoad {
  [super viewDidLoad];

  [self.navigationController setToolbarHidden:NO];

  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0f,0.0f,80.0f,40.0f)];
  label.text = @"last updated...";
  label.textAlignment = UITextAlignmentCenter;
  label.font = [UIFont systemFontOfSize:13.0];
  [self.navigationController.toolbar addSubview:label];

  UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
  UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Item1" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];

  NSArray *buttons = @[item1,item2,nil];
  [self.navigationController.toolbar setItems:buttons animated:NO];

解决方法

发现答案感谢苹果iOS论坛!

当您使用导航控制器的工具栏时,必须在视图控制器toolbaritems属性上设置工具栏按钮,而不是在实际工具栏上.

例如:

[self settoolbaritems:buttons animated:NO];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...