将新视图推送到导航堆栈时 UIToolbar 按钮消失

发布于 2024-10-14 15:04:56 字数 609 浏览 2 评论 0原文

我有一个基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謌踐踏愛綪 2024-10-21 15:04:56

工具栏按钮是给定视图的属性;当您将新视图推送到导航堆栈时,新视图的工具栏按钮将滑入到位。

工具栏本身似乎“属于”导航控制器;工具栏的可见性由UINavigationController的toolbarHidden属性控制,即

self.navigationController.toolbarHidden = YES;

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.,

self.navigationController.toolbarHidden = YES;
我一直都在从未离去 2024-10-21 15:04:56

要真正将工具栏从一个视图保留到下一个视图,您可以将 toolbarItems 属性从一个 UIView 复制到下一个。

To actually keep the toolbar from one view to the next, you can copy the toolbarItems property from one UIView to the next.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文