views:

39

answers:

2

Given the UINavigationController delegate methods:

-(void)navigationController:(UINavigationController*)navigationController (will/did)ShowViewController:(UIViewController*)viewController animated:(BOOL)animated

How do you tell or compare which view controller instance is relevant to the event?

I am developing an app that renders touch-navigable graphs using OpenGL. The root view contains the graph, and pushed navigation controllers contain options. I'd like to disable animation(rendering) of the graph when the user navigates away from it and re-enable it when they return.

(I know rendering should be done after the touch events and not constantly with an on/off; the template openGL code I built the app on doesn't make that an easy change but I'll get around to it eventually!)

(Oh another thing; it's a tab bar app with a navigation controller on each tab. For some reason view(did/will)(appear/disappear) events only seem to get fired when changing tabs, not the position on navigation controller stack.)

A: 

You would keep a list of ViewControllers and then compare to the one that is being shown.

You can compare by just comparing the references

for(UIViewController *vc in viewControllerArray)
{
  if(vs == viewController)
  //do stuff
}

Does this help or did i misunderstand something?

Tomen
Thanks for amazingly quick reply. I have a single reference to the root view controller and attempted to compare against that in a similar way; for some reason this is never true?
Tobster
+1  A: 

Fixed with the following:

if(viewController == [self.viewControllers objectAtIndex:0]) { NSString* bob = @"Your uncle"; }

Thanks for your direction.

Tobster
you are welcome
Tomen