I have created a custom navigation controller which I call CatalogueNavigationController
. This CatalogueNavigationController
has a property called currentLevel
which is of type int
.
On one of my view controllers that are presented within this navigation controller, I would like to get the CatalogueNavigationController
's currentLevel
value. However, when I try to reference it with self.navigationController.currentLevel
, I'm faced with an error that suggests that currentLevel isn't a property of UINavigationController
- I know, it's part of CatalogueNavigationController
.
CatalogueNavigationController
// .h
@interface CatalogueNavigationController : UINavigationController
@property int currentLevel;
// .m
@implementation CatalogueNavigationController
@synthesize currentLevel;
Initialising View Controller
CatalogueBrowser *catalogue = [[CatalogueBrowser alloc] initWithStyle:UITableViewStyleGrouped andQuery:nil];
CatalogueNavigationController *navigation = [[CatalogueNavigationController alloc] initWithRootViewController:catalogue];
navigation.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigation animated:YES];
CatalogueBrowser View Controller
NSLog(@"%i",self.navigationController.currentLevel); //ERROR: Property 'currentLevel' not found on object of type 'UINavigationController *'
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.
I could use Notifications to marry a variable on my view controller and on the CatalogueNavigationController, but surely there's a more elegant solution?
How can I reference self.navigationController to return the value of currentLevel
, but have it refer to the CatalogueNavigationController
and not UINavigationController?