[Segue destinationViewController].delegate is null?? 0x0??, Implementation with NavigationController

Check IF your Segue.destinationViewController is a navigationController !!!

*Problem*

If your segue.destinationViewController is navigationController, the below delegate is NULL as in this code
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showAdd"]) {
        [[segue destinationViewController] setDelegate:self];

    }
}

*Solution*

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showAdd"]) {
       
       // if the destinationViewController is navigationController
       
       myViewController * myVC = (myViewController *)[segue.destinationViewController topViewController];
       myVC.delegate = self;
 
    }
}



댓글

가장 많이 본 글