如何禁用当前视图中显示的 backBarButtonItem?

发布于 2025-01-08 03:14:20 字数 229 浏览 3 评论 0原文

将视图推送到 UINavigationController 堆栈并显示后,我需要在某些情况下禁用“后退”按钮,例如,当在该屏幕上编辑数据时。

以下隐藏了“后退”按钮

self.navigationItem.hidesBackButton=YES;

,但我需要禁用它。

还有其他几个关于如何隐藏它或建议首先不显示它的答案,但这些不是我需要实现的。

After a view has been pushed onto the UINavigationController stack and is displayed I need to disable the Back button under certain circumstances, e.g., when data is being edited on that screen.

The following hides the Back button

self.navigationItem.hidesBackButton=YES;

but I need to disable it.

There are several other answers about how to hide it or suggest not displaying it in the first place, but these are not what I need to implement.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

甜嗑 2025-01-15 03:14:20

您可以为 navigationController 的导航栏委托实现委托方法之一。看一下 [UINavigationBarDelegate navigationBar:shouldPopItem:] 方法。

从此方法返回 YES 或 NO 将启用或禁用后退按钮。

You could implement one of the delegate methods for your navigationController's navigation bar delegate. Take a look at the [UINavigationBarDelegate navigationBar:shouldPopItem:] method.

Returning YES or NO from this method will enable or disable the back button.

猥琐帝 2025-01-15 03:14:20

您可以实现一个 leftBarButtonItem (不可见且无效果)
将其添加到当前视图中(self.navigationItem.leftBarButtonItem)
并将其删除以访问您的后退按钮。

You could implement one leftBarButtonItem (invisible and without effect)
add it into your current view (self.navigationItem.leftBarButtonItem)
and remove it to access your backButton.

够钟 2025-01-15 03:14:20

如果您同意禁用整个导航栏,一个简单的解决方案是

self.navigationController.navigationBar.userInteractionEnabled = NO;

当然,如​​果您想保持启用其他栏按钮,则这不起作用。

If you're fine that the whole navigation bar is disabled, an easy solution is

self.navigationController.navigationBar.userInteractionEnabled = NO;

Of course this doesn't work if you have other bar buttons that you want to keep enabled.

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