I am opening a Modal view controller in my app, this modal view controller contains DatePicker.
The app's navigation hierarchy is
TabbarController->NavigationController->ViewController->ViewController
I have putted segue from first ViewController to second one and opening it in Modal segue.
I have putted Identifier to Modal segue, and connected the custom class too.
But when I write prepareForSegue
method the app is crashes with following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DatePickerViewController viewControllers]: unrecognized selector sent to instance 0xa082360'
The code for prepareForSegue
is
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"AddDate"])
{
UINavigationController *navigationController =segue.destinationViewController;
DatePickerViewController *datePickerViewController =[[navigationController viewControllers] objectAtIndex:0];
datePickerViewController.delegate = self;
}
}
I have followed this tutorial for Modal segue http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2.
I think you connected your segue with view controller not with navigation controller. To fix this replace your code with:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"AddDate"])
{
DatePickerViewController *datePickerViewController = (DatePickerViewController*)segue.destinationViewController;
datePickerViewController.delegate = self;
}
}