When using delegates, I usually only tell the next viewcontroller over in the UINavigationController that I want to set self as the delegate. I do this in my prepareForSegue method:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[segue.destinationViewController setDelegate:self];
}
This has always worked great. However, I’m trying to tell a viewController two indexes or two views over in the navController, that I want to set self as the delegate. I’ve tried every way that I can think of define the viewController receiver that I want to send the setDelegate method to but nothing seems to be working. Here is one example that Ive tried:
DateSelectViewController *dsvc = [[DateSelectViewController alloc] init];
[dsvc setDelegate:self];
The method is never being delegated and I know it has to do with the way I’m setting the delegate because I’ve ruled out every other possibility. How can I do this correctly?
You cannot do that directly because that view controller doesn’t exist yet. What you can do is this in the next one along:
If you have
A->B->Cin
Ayou’d have your original code:In
Byou’d have: