简体   繁体   English

使用Storyboard的UITabBarController自定义操作

[英]UITabBarController custom action with Storyboard

I would like to prompt a user to sign in with a UIAlertView when the user presses a certain tab bar item in a tab bar controller. 当用户按下选项卡栏控制器中的某个选项卡栏项时,我想提示用户使用UIAlertView登录。

This tab bar controller exists in storyboard, and as a result I'm not sure where i can do this. 此选项卡栏控制器存在于情节提要中,因此我不确定在哪里可以执行此操作。 Apple claims that UITabBarController shouldn't be subclassed, further adding to my confusion. 苹果声称UITabBarController不应该被子类化,这进一步加剧了我的困惑。 And furthermore, i am aware of UITabBarController's delegate pattern but i don't know what view controller i can hook it up to Note: My UITabBarController is generated from a modal segue from a UIViewController. 而且,我知道UITabBarController的委托模式,但我不知道我可以将其连接到哪个视图控制器。注意:我的UITabBarController是从UIViewController的模式序列生成的。

Thank you in advance. 先感谢您。

I found the answer to this when answering another of my own questions, here. 在这里回答自己的另一个问题时,我找到了答案

I used the uitabbarcontrollerdelegate and set that in the root controller. 我使用了uitabbarcontrollerdelegate并将其设置在根控制器中。

You can display your alert view when the selected view controller is displayed... Say you have a LoginViewController in the tab bar. 当显示选定的视图控制器时,您可以显示警报视图。例如,在选项卡栏中有一个LoginViewController inside that class create a method 在该类中创建一个方法

- (void)viewDidAppear:(BOOL)animated;

which displays the alert view 显示警报视图

Also look at the UITabBarDelegate 还要看看UITabBarDelegate

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM