Objective c 如何用新的viewController替换当前的viewController

Objective c 如何用新的viewController替换当前的viewController,objective-c,uinavigationcontroller,exc-bad-access,Objective C,Uinavigationcontroller,Exc Bad Access,我正在尝试用新的viewController替换当前的viewController。我以前可以这样做,但是我遇到了一些问题,访问不好 这是我想用新视图替换当前视图时将运行的代码 (将使用局部属性“self.some_data”(非原子,保留)调用该函数) 这里一切正常。问题是,如果我发布新的“viewController”,它会崩溃。如果我选择: [tempNavigationController popViewControllerAnimated:TRUE]; 我得到了一些非常奇怪的行为,控

我正在尝试用新的viewController替换当前的viewController。我以前可以这样做,但是我遇到了一些问题,访问不好

这是我想用新视图替换当前视图时将运行的代码

(将使用局部属性“self.some_data”(非原子,保留)调用该函数)

这里一切正常。问题是,如果我发布新的“viewController”,它会崩溃。如果我选择:

[tempNavigationController popViewControllerAnimated:TRUE];
我得到了一些非常奇怪的行为,控制器永远不会被替换,我返回到rootController,导航栏上有两层文本

如果我这样做:

[tempNavigationController pushViewController:viewController animated:FALSE];
我的访问和应用程序都不好。它以前有用,但现在不行了

我做错了什么


谢谢

控制器更换的使用类别:

//  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

如何/在何处发布新的viewController?用同样的方法?当我实现新的viewcontroller时,我得到了一个很好的建议。是否仍要控制过渡动画?
//  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