Skip to content

Instantly share code, notes, and snippets.

@Adlai-Holler
Created February 19, 2014 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adlai-Holler/9084922 to your computer and use it in GitHub Desktop.
Save Adlai-Holler/9084922 to your computer and use it in GitHub Desktop.
@implementation UINavigationController(Trim)
-(void)trimNavigationStack {
NSArray *vcs = [self.viewControllers subArrayWithRange:NSMakeRange(0,self.viewControllers.count - 1)];
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"trimmedVCs"];
[NSKeyedArchiver archiveRootObject:vcs toFile:file];
[self setViewControllers:@[self.viewControllers.lastObject] animated:NO];
}
-(void)untrimNavigationStack {
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"trimmedVCs"];
NSArray *unpacked = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
NSArray *newVCs = [unpacked arrayByAddingObjectsFromArray:self.viewControllers];
[self setViewControllers:newVCs animated:NO];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment