You need to use the delegate pattern to notify the modal "parent" that it should dismiss the modal view controller (animated:NO) and pop itself off the stack (animated:YES).
This is exactly what happens on the Calendar App - just pay attention to what happens to the navigation bar title when you confirm an event deletion - you can see the title quickly changing from "Edit" to "Event Details" as that view is being popped out off the navigation stack.
So in a nutshell, if we were talking about the calendar app, in your modal view controller, create a protocol with 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 your parent view controller, declare itself as the delegate for the modal and implement didConfirmEventDeletion
:
- (void)didConfirmEventDeletion
{
[self dismissModalViewControllerAnimated:NO];
[self.navigationController popViewControllerAnimated:YES];
}
PS: there might be a few typos as I wrote this code off memory...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…