Ios – Detect when Viewcontroller was Pushed

delegatesiosiphoneobjective cuinavigationcontroller

I am trying to detect when a ViewController was pushed.
So I followed the doc of Apple http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBarDelegate_Protocol/Reference/Reference.html , about NavegationBar delegate but I didnĀ“t figured out how to make it working successfully.
I placed on my code the following code in my ViewController but it doesn't detect it was pushing.
What I am doing wrong ?

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

Best Answer

Not clear what you are needing to do but there are several UIViewController methods for discerning its context. There are two below and a couple more in the docs

- (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);

}