我创建了 UITabBar (不是 UITabBarController)。如何调用 tabBar: didSelectItem?
我创建了 UITabBar (不是 UITabBarController)。如何调用 tabBar: didSelectItem?
I created UITabBar (not UITabBarController). How can I call tabBar: didSelectItem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论您的
UITabBar
视图如何显示,都非常符合 UITabBar 委托协议。当您初始化 UITabBar 时,将其委托分配给它所包含的视图。然后在您的视图
@interface
块中,在您的超类声明之后添加
。这会通知您的视图它包含一个UITabBar
,每当您选择UITabBar
的一部分时,我希望此视图发送消息tabBar: didSelectItem.
code> 从那时起,您就可以实现视图对选择某些项目的反应方式。有关更多信息,请查看 UITabBarDelegate 协议。
已更新评论
如果您想以编程方式调用它,您需要获取对您通过触摸调用时选择的项目的引用。所有选项卡栏项目都存储在一个数组中,因此您可以像这样引用它。
然后只需调用委托方法
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 aUITabBar
and whenever you select a portion ofUITabBar
, I want this view to be send the messagetabBar: 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.
then just call the delegate method