IOS extended UINavigationController returned from Stack to the previously marked position
This feature suddenly reminds me of the impression of the original code of a Java Data Structure last year. It contains a mark, a mark, and a mark ,... All forgot
However, after an inexplicable fire flower is left, we don't know where it is, so we can contact you,
But indeed, the mark was shown in my head at that moment, so I remembered it. Why? None!
Directly go to the Code, with the following instructions:
MarkNavigationController. h
#import
@interface MarkNavigationController : UINavigationController@property (nonatomic, strong) NSMutableArray *markControllers;@property (nonatomic, weak) UIViewController *lastMarkController;- (void)popToMarkViewControllerAnimated:(BOOL)animated;- (void)mark;@end
MarkNavigationController. m
# Import MarkNavigationController. h @ interface MarkNavigationController () @ end @ implementation MarkNavigationController-(void) viewDidLoad {[super viewDidLoad]; self. markControllers = [[NSMutableArray alloc] init];} # pragma mark--(void) popToMarkViewControllerAnimated :( BOOL) animated {if (self. markControllers. count> 0) {[self. markControllers removeObject: self. lastMarkController]; [self popToViewController: self. lastMarkController animated: YES]; if (self. markControllers. count> 0) {self. lastMarkController = self. markControllers. lastObject;} else {self. lastMarkController = nil ;}}// must match the previous method to avoid Memory leakage-(void) mark {self. lastMarkController = self. viewControllers. lastObject; [self. markControllers removeObject: self. lastMarkController]; [self. markControllers addObject: self. lastMarkController];} @ end
Call mark before pushing to mark the current view controller as the return point of the last outbound stack,
Then, no matter how many view controllers are pushed to the stack, when you call-(void) popToMarkViewControllerAnimated :( BOOL) animated;, the stack View Controller is automatically released until the Controller that is finally marked.
In fact, it adds a storage to the navigation controller.
Pre-stack pressure mark:
#pragma mark - NavigationBarButtonDelegate- (void)leftBarButtonPressed:(id)sender { NSLog(@leftBarButtonPressed); [self mark]; [self performSegueWithIdentifier:@SegueToGetClassCode sender:sender];}
The output stack is returned to the final mark position:
#pragma mark -- (IBAction)popToMarkButtonPressed:(id)sender { [self popToMarkViewControllerAnimated:YES];}