将新视图推送到导航堆栈时 UIToolbar 按钮消失
我有一个基于 UINavigationController
的 iPhone 应用程序,底部有一个 UIToolbar
,其中有我通过 Interface Builder 创建的各种按钮。当我使用 [navigationController PushViewController:animated:] 时,我的新视图按预期滑入到位,但所有按钮都从工具栏中消失 - 工具栏本身保持可见,它只是完全空的。
如何让按钮保持不动?
这是我响应用户按下工具栏按钮之一然后显示新视图的部分:
- (IBAction)clickSettings:(id)sender {
NSLog(@"Clicked on 'Settings' button");
SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
[navigationController pushViewController:settingsViewController animated:YES];
}
I have an iPhone app based around a UINavigationController
with a UIToolbar
at the bottom with various buttons in it that I created through the Interface Builder. When I use [navigationController pushViewController:animated:]
my new view slides into place as expected but then all of the buttons are disappearing from the toolbar - the toolbar itself stays visible, it's just completely empty.
How do I get the buttons to stay put?
Here's the bit where I respond to the user pressing one of the toolbar buttons that then shows the new view:
- (IBAction)clickSettings:(id)sender {
NSLog(@"Clicked on 'Settings' button");
SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
[navigationController pushViewController:settingsViewController animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
工具栏按钮是给定视图的属性;当您将新视图推送到导航堆栈时,新视图的工具栏按钮将滑入到位。
工具栏本身似乎“属于”导航控制器;工具栏的可见性由UINavigationController的toolbarHidden属性控制,即
The tool bar buttons are the property of a given view; when you push a new view on to the navigation stack, the tool bar buttons of the new view will slide in to place.
The tool bar itself seems to "belong" to the navigation controller; visibility of the toolbar is controlled by the UINavigationController toolbarHidden property, i.e.,
要真正将工具栏从一个视图保留到下一个视图,您可以将
toolbarItems
属性从一个UIView
复制到下一个。To actually keep the toolbar from one view to the next, you can copy the
toolbarItems
property from oneUIView
to the next.