首先,如Apple文档中所述,选项卡栏应位于根级别,即添加到窗口。这是正确行为的关键。
其次,你可以使用UITabBarDelegate
/UINavigationBarDelegate
转发手动的通知,但我发现,要得到从整体层次要求正常工作,我所要做的就是手动调用
[tabBarController viewWillAppear:NO];
[tabBarController viewDidAppear:NO];
和
[navBarController viewWillAppear:NO];
[navBarController viewDidAppear:NO];
..只是一旦相应的控制器上设置的视图控制器之前(分配后右)。从此,它在其子视图控制器上正确调用了这些方法。
我的层次结构是这样的:
window
UITabBarController (subclass of)
UIViewController (subclass of) // <-- manually calls [navController viewWill/DidAppear
UINavigationController (subclass of)
UIViewController (subclass of) // <-- still receives viewWill/Did..etc all the way down from a tab switch at the top of the chain without needing to use ANY delegate methods
只需调用标签/导航控制器在第一时间确保所有事件正确转发上提到的方法。它阻止了我需要从UINavigationBarDelegate
/UITabBarControllerDelegate
方法手动调用它们。
旁注: 奇怪的是,当它没有工作,私有方法
- (void)transitionFromViewController:(UIViewController*)aFromViewController toViewController:(UIViewController*)aToViewController
..你可以从调用堆栈上看到一个工作的实施,通常调用viewWill/Did..
的方法,但并没有到我执行了上述(即使它被称为)。
我认为这是非常重要的UITabBarController
是在窗口级别,但文件似乎支持这一点。
希望明确(ish),很乐意回答更多问题。
来源
2011-07-26 17:10:55
Sam
直到我意识到我是错误理解用途的UIViewController子类通常我有这个问题。看看这个问题。 http://stackoverflow.com/questions/5691226/am-i-abusing-uiviewcontroller-subclassing/5691708#comment-6507338 – averydev 2011-04-17 23:26:47
请当心!不再适用于iOS 5!调用viewWillAppear和viewDidAppear自动调用 – 2011-11-10 17:23:51