简体   繁体   English

iPhone SDK:如何确定TabBarController中的最后一个活动标签?

[英]iPhone SDK: How can I determine the last active tab in a TabBarController?

One of the tab bar controller tabs in my iPhone app changes what it displays based on where the user arrived from (which other tabs). 我的iPhone应用程序中的一个选项卡栏控制器选项卡根据用户来自何处(其他选项卡)来更改其显示内容。 For example, if the tabs are A, B, C and D, the C tab will display a picture if the user was previously on tab A, but text if the user was previously on tab B. 例如,如果选项卡是A,B,C和D,则如果用户先前位于选项卡A上,则C选项卡将显示图片,而如果用户先前位于选项卡B上则C将显示文本。

I'm not sure how to implement this without subclassing the TabBarController (which Apple documentation discourages). 我不确定如何在不继承TabBarController的情况下实现这一点(Apple文档不鼓励这样做)。 TabBarController has a property for currently active controller, and a list of all controllers in the tab bar, but no way to see the 'tab bar controller traversion tree/stack', so to speak. TabBarController具有当前活动控制器的属性,以及选项卡栏中所有控制器的列表,但无法看到“选项卡控制器遍历树/堆栈”。 Any thoughts? 有什么想法吗?

Instead of subclass UITabBarController you can set a delegate and keep track of the last selected view controller via 可以代替UITabBarController的子类来设置委托,并通过以下方式跟踪最后选择的视图控制器

- (void)tabBarController:(UITabBarController *)tabBarController
    didSelectViewController:(UIViewController *)viewController;

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

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