• <small id='pOuiQ'></small><noframes id='pOuiQ'>

    <tfoot id='pOuiQ'></tfoot>

        <bdo id='pOuiQ'></bdo><ul id='pOuiQ'></ul>
      <legend id='pOuiQ'><style id='pOuiQ'><dir id='pOuiQ'><q id='pOuiQ'></q></dir></style></legend>
        <i id='pOuiQ'><tr id='pOuiQ'><dt id='pOuiQ'><q id='pOuiQ'><span id='pOuiQ'><b id='pOuiQ'><form id='pOuiQ'><ins id='pOuiQ'></ins><ul id='pOuiQ'></ul><sub id='pOuiQ'></sub></form><legend id='pOuiQ'></legend><bdo id='pOuiQ'><pre id='pOuiQ'><center id='pOuiQ'></center></pre></bdo></b><th id='pOuiQ'></th></span></q></dt></tr></i><div id='pOuiQ'><tfoot id='pOuiQ'></tfoot><dl id='pOuiQ'><fieldset id='pOuiQ'></fieldset></dl></div>

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

        时间:2023-06-11
        <tfoot id='5XTm3'></tfoot>
          <bdo id='5XTm3'></bdo><ul id='5XTm3'></ul>
            <legend id='5XTm3'><style id='5XTm3'><dir id='5XTm3'><q id='5XTm3'></q></dir></style></legend>

                  <small id='5XTm3'></small><noframes id='5XTm3'>

                1. <i id='5XTm3'><tr id='5XTm3'><dt id='5XTm3'><q id='5XTm3'><span id='5XTm3'><b id='5XTm3'><form id='5XTm3'><ins id='5XTm3'></ins><ul id='5XTm3'></ul><sub id='5XTm3'></sub></form><legend id='5XTm3'></legend><bdo id='5XTm3'><pre id='5XTm3'><center id='5XTm3'></center></pre></bdo></b><th id='5XTm3'></th></span></q></dt></tr></i><div id='5XTm3'><tfoot id='5XTm3'></tfoot><dl id='5XTm3'><fieldset id='5XTm3'></fieldset></dl></div>
                    <tbody id='5XTm3'></tbody>

                  本文介绍了如何用新的 viewController 替换当前的 viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试用新的 viewController 替换当前的 viewController.我以前能够做到这一点,但我遇到了 BAD_ACCESS 的一些问题.

                  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 that will run when I want to replace the current view with a new one.

                  (将使用本地属性self.some_data"(非原子,保留)调用该函数)

                  (The function will be called using a local property "self.some_data" (nonatomic, retain))

                  -(void) labelSelected:(SomeDataObject*) some_data{ 
                     SomeViewController *viewController = (SomeViewController*)[[ClassManager sharedInstance] viewControllerForClassIdentifier:@"com.somename" fromPlistFileName:@"iPhoneScreenList"];
                  
                  
                     viewController.data = (NSObject*)some_data;
                     [some_data retain];
                  
                     //[self.navigationController pushViewController:viewController animated:YES];
                  
                     UINavigationController *tempNavigationController = self.navigationController;
                  
                     [[self retain] autorelease];
                  
                     [tempNavigationController popViewControllerAnimated:FALSE];
                     [tempNavigationController pushViewController:viewController animated:TRUE];
                  }
                  

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

                  Here everything works fine. The issue is that if I release the new "viewController" it crashes. And if I choose:

                  [tempNavigationController popViewControllerAnimated:TRUE];
                  

                  我得到了一些非常奇怪的行为,控制器永远不会被替换,我返回到 rootController 并且导航栏上有两层文本.

                  I get some really wierd behaviour where the controller never gets replace and I return to the rootController and the navigation bar has two layers of text on it.

                  如果我这样做:

                  [tempNavigationController pushViewController:viewController animated:FALSE];
                  

                  我得到 BAD_ACCESS 并且应用程序崩溃.它以前有效,但现在无效.

                  I get BAD_ACCESS and the application chrashes. It worked before but not anymore.

                  我做错了什么?

                  谢谢!

                  推荐答案

                  使用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
                  

                  这篇关于如何用新的 viewController 替换当前的 viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:滑动回根视图控制器时,大型导航栏背景颜色变得清晰 下一篇:为什么这段代码使用 presentModalViewController?(不是 pushViewController)

                  相关文章

                    <legend id='RFxun'><style id='RFxun'><dir id='RFxun'><q id='RFxun'></q></dir></style></legend>
                      <tfoot id='RFxun'></tfoot>
                    1. <i id='RFxun'><tr id='RFxun'><dt id='RFxun'><q id='RFxun'><span id='RFxun'><b id='RFxun'><form id='RFxun'><ins id='RFxun'></ins><ul id='RFxun'></ul><sub id='RFxun'></sub></form><legend id='RFxun'></legend><bdo id='RFxun'><pre id='RFxun'><center id='RFxun'></center></pre></bdo></b><th id='RFxun'></th></span></q></dt></tr></i><div id='RFxun'><tfoot id='RFxun'></tfoot><dl id='RFxun'><fieldset id='RFxun'></fieldset></dl></div>

                      <small id='RFxun'></small><noframes id='RFxun'>

                      • <bdo id='RFxun'></bdo><ul id='RFxun'></ul>