I have an iPad view that presents a modal form sheet that is essentially a ‘settings’ view.
From there the user can go to a specific setting. I need to be able to refresh the main iPad view when the modal view is dismissed.
Therefore, I need a delegate protocol to call -(void)refreshTable when the modal view is dismissed. This wouldn’t be a problem except when I present the modal view, the delegate I need to assign, is a view that is ‘pushed’ from the presented view. (Screenshot)

Here is how I’m presenting the modal form sheet:
I’m encapsulating it in a UINavigationController because it needs to push other views.
(I would just assign the delegate here, but the view with the protocol gets pushed from AddView) NewAftpViewController is the view controller which has the protocol.
-(void)presentAddView:(id)sender {
AddView *avc = [self.storyboard instantiateViewControllerWithIdentifier:@"add"];
UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:avc];
navcont.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navcont animated:YES completion:NULL];
}
And here is my protocol in the pushed view:
@protocol RefreshAfterAddingNewAftpDelegate
-(void)refreshTable;
@end
@interface NewAftpViewController : UIViewController
@property (nonatomic, retain) id <RefreshAfterAddingNewAftpDelegate> refreshAfterAddingNewAftpDelegate;
@end
I can see two ways to do this. You should be able to get a reference to that left most controller in your post with
[self.navigationController presentingViewController]— you’ll need to castself.navigationControllerto whatever class that is. Then in yourNewAftpViewController, you can set the delegate like this:But this seems to defeat the purpose of using a delegate — the delegator is not supposed to know what class the delegate is, but here you have to set it explicitly. Instead of using a delegate, you could just call a method on that controller directly.
I think the better way, in situations like this, is to use an
NSNotification. That seems cleaner and simpler to me. Just post a notification fromNewAftpViewController, and have your first controller listen for it.