I'm trying to customize the behavior of my application's navigation bar. I've managed to subclass the UINavigationController to run custom code every time I push the back button, yet still, the navigation bar title changes and pressing the button again ignores my code (Maybe because it's and entire different controller?).
What I want to achieve is to tell the UINavigationController to ignore presses to the back button under certain conditions (which are already defined and controller from the custom Navigation Controller), and thus keeping the current view and navigation bar intact.
How can I achieve that? I've only overrode the (UIViewController *)popViewControllerAnimated:(BOOL)animated function.
My code:
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
if(self.auxController == nil)
{
NSLog(@"[CustomNavigationController.m]: WARNING: No Auxiliar Controller assigned to Navigation controller");
return [super popViewControllerAnimated:animated];
}
else
{
NSLog(@"[CustomNavigationController.m]: Navigation Stack has %d remaining levels",[[[self auxController] parentLayout] count]);
if([[[self auxController] parentLayout] count] > 0)
{
NSLog(@"[CustomNavigationController.m]: Falling to previous navigation level");
[[self auxController] navBack];
}
else
{
NSLog(@"[CustomNavigationController.m]: No more navigation levels in stack, falling to previous view");
self.auxController = nil;
return [super popViewControllerAnimated:animated];
}
}
return nil;
}