更新时间:2023-12-02 22:39:22
使用category替换控制器:
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