![](/img/trans.png)
[英]UISplitViewController with UIToolbar not showing UIBarButtonItem in landscape mode
[英]UIToolbar not showing UIBarButtonItem
我正在使用故事板,我有一个分割视图,其中master是一个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];
感谢Apple iOS论坛找到了答案!
使用导航控制器的工具栏时,必须在活动视图控制器的toolbarItems
属性上设置工具栏按钮,而不是在实际导航控制器的工具栏本身上。
显示工具栏
导航控制器对象管理其视图层次结构中的可选工具栏。 显示时,此工具栏从活动视图控制器的
toolbarItems
属性获取其当前项集。 当活动视图控制器更改时,导航控制器会更新工具栏项以匹配新视图控制器,并在适当时将新项目设置为动态位置。
例如:
[self setToolbarItems:buttons animated:NO];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.