检查Viewcontroller何时被推送

Ben*_*Ben 5 iphone delegates objective-c uinavigationcontroller ios

我试图检测何时推送ViewController.所以我按照Apple的文档http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBarDelegate_Protocol/Reference/Reference.html,关于NavegationBar委托,但我没有弄清楚如何制作它工作顺利.我在我的代码中放置了我的ViewController中的以下代码,但它没有检测到它正在推送.我做错了什么?

- (void)navigationBar:(UINavigationBar *)navigationBar didPushItem:(UINavigationItem *)item, {
    NSLog(@"didPushItem: %@", item);
    [self showimage];
}
Run Code Online (Sandbox Code Playgroud)

No *_*ing 13

不清楚你需要做什么,但有几种UIViewController方法可以辨别其背景.下面有两个,文档中还有两个

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    BOOL pushed = [self isMovingToParentViewController];

    printf("viewWillAppear     %d\n", pushed);

}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    BOOL popped = [self isMovingFromParentViewController];

    printf("viewWillDisappear     %d\n", popped);

}
Run Code Online (Sandbox Code Playgroud)


Cez*_*zar 5

您应该实现UINavigationControllerDelegateUIViewControllerUINavigationController相关的任务.

以下是文档的链接:http: //developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationControllerDelegate_Protocol/Reference/Reference.html

您想要的特定方法(如" navigationController:didPushViewController:animated:")在协议中不存在.

但是,我相信你可以使用它实现所需的行为navigationController:willShowViewController:animated:.请注意,此方法在显示视图之前UIViewController以及在将其推入UINavigationController堆栈之后调用.