处理对选项卡栏控制器标题中按钮的点击

发布于 2024-12-27 13:17:01 字数 124 浏览 1 评论 0原文

我有一个带有多个选项卡/视图的选项卡栏控制器。我已将“帮助”栏按钮项目添加到选项卡栏控制器的顶部导航栏。

我如何处理此按钮的点击,最好取决于我当时所处的视图?

我只是在单击时弹出一个警报,即。无需导航。

I have a tab bar controller with a number of tabs/views. I have added a "Help" bar button item to the tab bar controller's top navigation bar.

How do I handle clicks of this button, ideally depending on which view I am in at the time?

I am simply going to pop up an alert when it is clicked, ie. No navigation required.

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

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

发布评论

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

评论(2

故事灯 2025-01-03 13:17:01

理想情况下,此“帮助”选项卡不应根据上下文(即先前选择的选项卡)更改其行为。用户会感到困惑,因为内容不是恒定的。

如果您在选择选项卡时发出“弹出警报”,这似乎也可能是因为糟糕的用户体验而被拒绝的依据。选择一个选项卡应显示该选项卡的新视图。您还必须处理如何将用户静默移回到上一个选项卡,和/或不更改所选选项卡索引。这又是一个麻烦的用户体验。

如果您坚持采用这种设计(我相信这会让您的应用程序被拒绝),您可以使用 UITabBarControllerDelegate 控制 UITabBarController 的行为。

我建议你改变你的设计。

Ideally, this "help" tab should not change its behaviour depending on context, i.e., what tab was previously selected. The user will get confused because the content will not be constant.

If you raise a "pop up alert" when the tab is selected, this also seems like a basis for rejection because of bad UX. Selecting a tab should display a new view for that tab. You'd also have to deal with how to move the user back to the previous tab silently, and/or not change the selected tab index. Again, this is troublesome UX.

If you insist on going with this design -- which I believe will get your app rejected -- you can use a UITabBarControllerDelegate to control the behaviour of the UITabBarController.

I recommend you change your design instead.

心意如水 2025-01-03 13:17:01

我已经设法让这个工作了。我认为您误解了:我有一个选项卡栏控件,它通过根据所选选项卡推送视图来正常运行。我只是想要在导航栏右侧有一个帮助按钮,该按钮会打开一个警报,其中包含有关您当时所在的选项卡的信息。我已经这样做了:

在标签栏控制器推送的每个视图的 viewDidAppear 中:

UIBarBarButtonItem *helpButton = [[UIBarBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStylePlain target:self action:@selector(helpButtonPressed))];
self.tabBarController.navigationItem.rightBarButtonItem=helpButton;

然后我有 helpButtonPressed 函数来处理按钮单击,在我的例子中是通过弹出并发出有关该选项卡的一些帮助信息的警报。

I've managed to get this working. I think you misunderstood: I have a tab bar control which operates normally by pushing views based on the tab selected. I simply wanted a help button on the right of the navigation bar that would open an alert with information about the tab you happen to be in at the time. I have done it like this:

In viewDidAppear of each view pushed by the tab bar controller:

UIBarBarButtonItem *helpButton = [[UIBarBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStylePlain target:self action:@selector(helpButtonPressed))];
self.tabBarController.navigationItem.rightBarButtonItem=helpButton;

I then have the helpButtonPressed function to handle the button click, in my case by popping up and alert with some help info regarding the tab.

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