Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C: Using self.navigationController with a Custom UINavigationController
    text
    copied!<p>I have created a custom navigation controller which I call <code>CatalogueNavigationController</code>. This <code>CatalogueNavigationController</code> has a property called <code>currentLevel</code> which is of type <code>int</code>.</p> <p>On one of my view controllers that are presented within this navigation controller, I would like to get the <code>CatalogueNavigationController</code>'s <code>currentLevel</code> value. However, when I try to reference it with <code>self.navigationController.currentLevel</code>, I'm faced with an error that suggests that currentLevel isn't a property of <code>UINavigationController</code> - I know, it's part of <code>CatalogueNavigationController</code>.</p> <p>CatalogueNavigationController</p> <pre><code>// .h @interface CatalogueNavigationController : UINavigationController @property int currentLevel; // .m @implementation CatalogueNavigationController @synthesize currentLevel; </code></pre> <p>Initialising View Controller</p> <pre><code>CatalogueBrowser *catalogue = [[CatalogueBrowser alloc] initWithStyle:UITableViewStyleGrouped andQuery:nil]; CatalogueNavigationController *navigation = [[CatalogueNavigationController alloc] initWithRootViewController:catalogue]; navigation.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:navigation animated:YES]; </code></pre> <p>CatalogueBrowser View Controller</p> <pre><code>NSLog(@"%i",self.navigationController.currentLevel); //ERROR: Property 'currentLevel' not found on object of type 'UINavigationController *' </code></pre> <p>The currentLevel variable is decremented when a viewController is popped and incremented when a viewController is pushed, to allow me to keep track of 'how deep' into the navigation the user is. So I need to return it's current state.</p> <p>I could use Notifications to marry a variable on my view controller and on the CatalogueNavigationController, but surely there's a more elegant solution?</p> <p>How can I reference self.navigationController to return the value of <code>currentLevel</code>, but have it refer to the <code>CatalogueNavigationController</code> and not UINavigationController?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload