I\'ve been toying around with state restoration. In the code below, the scroll position of the UITableViewController gets restored, however, if I were to tap through into the de
Since you are doing this in code and not via Storyboard, you will need to provide not only a restorationIdentifier
but also a restorationClass
to you detail view controller.
You could leave it unassigned in which case -(UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
gets called on the application delegate to make the object (view controller with a restorationIdentifier
but no restorationClass
).
Try the following (please note the UIViewControllerRestoration
protocol):
@interface MyViewController ()
@end
@implementation
- (id)init
{
self = [super init];
if (self) {
// Custom initialization
}
if( [self respondsToSelector:@selector(restorationIdentifier)] ){
self.restorationIdentifier = @"DetailViewController";
self.restorationClass = [self class];
}
return self;
}
#pragma mark - State restoration
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
UIViewController *viewController = [[self alloc] init];
return viewController;
}
@end
Also note that this is a very simple example, usually you might have a lot more interesting things going on in -viewControllerWithRestorationIdentifierPath:coder: