我创建了 UITabBar (不是 UITabBarController)。如何调用 tabBar: didSelectItem?

发布于 2024-10-16 20:08:10 字数 72 浏览 4 评论 0原文

我创建了 UITabBar (不是 UITabBarController)。如何调用 tabBar: didSelectItem?

I created UITabBar (not UITabBarController). How can I call tabBar: didSelectItem?

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

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

发布评论

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

评论(1

这样的小城市 2024-10-23 20:08:10

无论您的 UITabBar 视图如何显示,都非常符合 UITabBar 委托协议。

当您初始化 UITabBar 时,将其委托分配给它所包含的视图。然后在您的视图 @interface 块中,在您的超类声明之后添加 。这会通知您的视图它包含一个 UITabBar ,每当您选择 UITabBar 的一部分时,我希望此视图发送消息 tabBar: didSelectItem. code> 从那时起,您就可以实现视图对选择某些项目的反应方式。

有关更多信息,请查看 UITabBarDelegate 协议。

已更新评论

如果您想以编程方式调用它,您需要获取对您通过触摸调用时选择的项目的引用。所有选项卡栏项目都存储在一个数组中,因此您可以像这样引用它。

UITabBarItem *tabItem = [self.tabBar.items objectAtIndex:(index of object)];

然后只需调用委托方法

[self tabBar:self.tabBar didSelectItem:tabItem]; 

Whatever view your UITabBar is displayed in much conform to the UITabBar Delegate Protocol.

When you initialize your UITabBar, assign it's delegate to the view it's contained within. Then within your views @interface block add <UITabBarDelegate> after your superclass declaration. This informs your view that it contains a UITabBar and whenever you select a portion of UITabBar, I want this view to be send the message tabBar: didSelectItem. From there on out it's up to you to implement how the view reacts to selecting certain items.

For more information check out the UITabBarDelegate Protocol.

Updated for comment

If you want to call it programatically you need to get a reference to the item you would have selected if you were calling this by a touch. All tab bar items are stored in an array so you can just reference it like so.

UITabBarItem *tabItem = [self.tabBar.items objectAtIndex:(index of object)];

then just call the delegate method

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