How to replace current viewController with a new viewController

后端 未结 1 844
清歌不尽
清歌不尽 2021-01-03 03:07

I\'m trying to replace my current viewController with a new one. I\'ve been able to do this before but I\'m having some issues with BAD_ACCESS.

This is the code tha

相关标签:
1条回答
  • 2021-01-03 03:56

    Use category for controller replace:

    //  UINavigationController+ReplaceStack.h
    
    
    @interface UINavigationController (ReplaceStack)
    
    - (void) replaceLastWith:(UIViewController *) controller;
    
    @end
    
    //  UINavigationController+ReplaceStack.m
    
    #import "UINavigationController+ReplaceStack.h"
    
    @implementation UINavigationController (ReplaceStack)
    
    - (void) replaceLastWith:(UIViewController *) controller {
        NSMutableArray *stackViewControllers = [NSMutableArray arrayWithArray:self.viewControllers];
        [stackViewControllers removeLastObject];
        [stackViewControllers addObject:controller];
        [self setViewControllers:stackViewControllers animated:YES];
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题