IPhone - 如何检测切换选项卡视图和BackBarButtonItem?

时间:2012-08-22 08:44:56

标签: iphone uinavigationcontroller

我需要在基于Tab的应用程序上切换选项卡时检测Navigation BackBarButton和View。 我怎样才能做到这一点。我需要代码示例

1 个答案:

答案 0 :(得分:1)

在推送加载的viewController之后绘制NavigationBar。此外,modalViewController位于navigationController上'stack'中topViewController的顶部。 并检测UINavigationController的后退按钮是通过验证当前视图控制器不在导航控制器的视图控制器堆栈中。 它可以安全地检查这个条件 - (void)viewDidDisappear:(BOOL)在逻辑上动画,到调用方法的时候,视图控制器极有可能从堆栈中删除。 可以使用navigationController.topViewController检测切换视图或相同视图,并使用isKindOfClass触发backBarButtonItem。 以下是适用于我的示例。

- (void)viewDidDisappear:(BOOL)animated{
if ([self.navigationController.topViewController isKindOfClass:[SDWebImageRootViewController class]]) {
    NSLog(@"Is kind of");
    //condition goes here
  }
if (!self.navigationController.topViewController) {
    NSLog(@"Is kind of topViewController");
   //condition goes here
}

}