I am attempting to use iOS 6+ (my app is 7.0+) State Preservation to preserve a view that is presented modally from another View Controller. As such it, has the typical modal view controller dismissal pattern:
TNTLoginViewController.h contains
@protocol TNTLoginViewControllerDelegate <NSObject>
- (void)TNTLoginViewControllerDismiss:(TNTLoginViewController *)controller;
@end
@interface TNTLoginViewControllerDelegate : NSObject
@interface TNTLoginViewController : UIViewController
@property (weak, nonatomic) IBOutlet id <TNTLoginViewControllerDelegate> delegate;
- (IBAction)getStarted:(id)sender;
@end
getStarted: implementation
- (IBAction)getStarted:(id)sender
{
// Perform login
...
// Dismiss me
[self.delegate TNTLoginViewControllerDismiss:self];
}
TNTLoginViewControllerDismiss: method on delegate, which presented the modal
- (void)TNTLoginViewControllerDismiss:(TNTLoginViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
And it all works like a charm! Until State Preservation. Simply put, I don't know how TNTLoginViewController would preserve its delegate. I understand why it can't: it's just a pointer! So I tried various ways of deriving the delegate instead:
- Restoration class: sadly, as a class method,
viewControllerWithRestorationIdentifierPath:coder:
doesn't help me point to my specific presenting View Controller. - Set my presenting VC as my modal VC's delegate in the Storyboard: Xcode wouldn't let me draw that connection, even when my presenting VC's class publicly adopted the
TNTLogingViewControllerDelegate>
protocol in its header. That may be a separate issue, or this may not be allowed. - Use the application-delegate-level
application:viewControllerWithRestorationIdentifierPath:coder:
to return a modal view controller with its delegate set to my presenting View Controller. I have to be able to derive that presenting VC from the App Delegate, but it might work.
I'm going with #3 for now, but if there is a better solution someone could recommend, I would be thrilled.
Setups that would yield similar problems:
- Setting a data source, say for a table view.