You need to use the delegate template to notify the modal “parent” so that it rejects the modal view controller (animated: NO) and pops out of the stack (animated: YES).
This is exactly what happens in the Calendar application - just pay attention to what happens with the title of the navigation bar when you confirm the deletion of the event. You can see the name that quickly changes from “Change” to “Event Details” as this type is unloaded from the navigation stack.
So, if we're talking about a calendar application, create a protocol in your modular view controller using a method like didConfirmEventDeletion
:
@protocol ModalViewDelegate <NSObject> - (void)didConfirmEventDeletion; @end @interface ModalViewController... @property (nonatomic, assign) id<ModalViewDelegate> delegate; @end
And implementation:
@implementation ModalViewController - (void)deleteEventMethod { ... if ([self.delegate respondsToSelector:@selector(didConfirmEventDeletion)]) [self.delegate didConfirmEventDeletion]; }
Then, in the controller of the parent view, declare yourself a delegate for the modal and implement didConfirmEventDeletion
:
- (void)didConfirmEventDeletion { [self dismissModalViewControllerAnimated:NO]; [self.navigationController popViewControllerAnimated:YES]; }
PS: there may be several typos since I wrote this code without memory ...
source share