IOS extended UINavigationController returned from Stack to the previously marked position

Source: Internet
Author: User

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];}


 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.