My app is crashing when trying to access a method in my parentViewController. Here is the layout in StoryBoard
MainViewController = STLMMainViewController (ParentViewController)
Scene1 = STLMTimeDateViewController (ChildViewController)
Here is the code for STLMTimeDateViewController
#import "STLMTimeDateViewController.h"
#import "STLMMainViewController.h"
@interface STLMTimeDateViewController ()
@property (nonatomic, strong) STLMMainViewController *stlmMainViewController;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"The name of the controller %@",self.navigationController.parentViewController);
stlmMainViewController= (STLMMainViewController *) self.parentViewController;
[stlmMainViewController locationButtonSelected]; // This is where the App crashes
NSLog(@"TimeDateController");
}
The App Runs, but when STLMMainViewController is called, the app crashes with the following error:
2013-02-10 16:33:57.422 MyApp[9120:c07] The name of the controller <STLMMainViewController: 0x83850d0>
2013-02-10 16:33:57.434 MyApp[9120:c07] -[UINavigationController locationButtonSelected]: unrecognized selector sent to instance 0x8371a70
If I remove the following line:
stlmMainViewController = (STLMMainViewController *) self.parentViewController;
and just leave
[stlmMainViewController locationButtonSelected];
The App runs, no error, but the following method in [STLMMainViewController locationButtonSelected] does not get called (I never see the log):
-(void)locationButtonSelected
{
[LocationButton setSelected:YES];
[eatDrinkbutton setSelected:NO];
[timeCalButton setSelected:NO];
[carButton setSelected:NO];
[contactButton setSelected:NO];
NSLog(@"LocationButtonSelected Method");
}
All the properties in the locationButtonSelected method and the method itself is declared in .h of STLMMainViewController for public access.
Thanks