I faced the same problem, and a better solution was creating a "DismissViewProtocol" as follow:
File: DismissViewProtocol.h
@protocol DismissViewProtocol <NSObject>
-(void)dismissView:(id)sender;
@end
In my B-modal view, let's response for the delegate method:
in my b.h file:
#import "DismissViewProtocol.h"
@interface B-Modal : UIViewController <DismissViewProtocol>
...
@end
in my b.m file:
-(void) dismissView:(id)sender
{
[((UIViewController *) sender) dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:YES];
}
In the same B-view controller, when I call the
Next, in my B modal view, when I call the other modal view C, supposing that for segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
((C-ViewController *)segue.destinationViewController).viewDelegate=self;
}
Finally, in my c.h file, lets prepare for the delegate:
@property(nonatomic, weak) id <DismissViewProtocol> viewDelegate;
And in my c.m file, I just tell my viewDelegate to dismiss my modal view controller and itself:
-(void)closeBothViewControls
{
[self.viewDelegate dismissView:self];
}
And that's it.
Hope it works for all of you.