【发布时间】:2013-07-08 19:20:39
【问题描述】:
我有很多人已经报告过的问题,didSelectViewController 没有被调用,但在我的情况下,它有时会被调用。我有三个选项卡和三个视图控制器。每次用户按下第二个或第三个选项卡时,我都需要执行一些代码。在我的 SecondViewController 和 ThirdViewController 中,我有:
UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[tabBarController setDelegate:self];
现在 SecondViewController 一切正常,每次按下第二个选项卡时都会调用 didSelectViewController。同样在 ThirdViewController didSelectViewControllergets 中,每次按下第三个选项卡时都会调用,但仅在同时未按下第二个栏时调用。因此,当我在 FirstViewController 和 ThirdViewController 之间来回切换时,一切正常。但是当我进入像 first->second->third 这样的模式时,didSelectViewController 不会在 ThirdViewController 中被调用。同样,当我第一次在 ThirdViewController 中调用但不是第二次时,我像 first->third->second->third didSelectViewController 一样。有什么想法吗?
【问题讨论】:
-
在您删除之前我碰巧注意到您对我的答案的评论,并且我已经编辑了我的答案,并提供了一些提示如何将示例代码集成到您的项目中。