1. <small id='uJMaX'></small><noframes id='uJMaX'>

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

      <tfoot id='uJMaX'></tfoot>
    1. <legend id='uJMaX'><style id='uJMaX'><dir id='uJMaX'><q id='uJMaX'></q></dir></style></legend>
      • <bdo id='uJMaX'></bdo><ul id='uJMaX'></ul>

      如何弹回根视图控制器,然后推送到不同的视图?

      时间:2023-06-10
        • <bdo id='sYtc0'></bdo><ul id='sYtc0'></ul>
        • <small id='sYtc0'></small><noframes id='sYtc0'>

        • <tfoot id='sYtc0'></tfoot>
          1. <legend id='sYtc0'><style id='sYtc0'><dir id='sYtc0'><q id='sYtc0'></q></dir></style></legend>

                <tbody id='sYtc0'></tbody>
                <i id='sYtc0'><tr id='sYtc0'><dt id='sYtc0'><q id='sYtc0'><span id='sYtc0'><b id='sYtc0'><form id='sYtc0'><ins id='sYtc0'></ins><ul id='sYtc0'></ul><sub id='sYtc0'></sub></form><legend id='sYtc0'></legend><bdo id='sYtc0'><pre id='sYtc0'><center id='sYtc0'></center></pre></bdo></b><th id='sYtc0'></th></span></q></dt></tr></i><div id='sYtc0'><tfoot id='sYtc0'></tfoot><dl id='sYtc0'><fieldset id='sYtc0'></fieldset></dl></div>
              • 本文介绍了如何弹回根视图控制器,然后推送到不同的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个具有 3 个视图控制器的简单应用程序.根视图控制器是一个item Listing,基本的表格视图.在这个视图控制器之外,我基于一些用户交互推送了两个不同的视图控制器 - create item 视图控制器或 view item 视图控制器.

                I am writing a simple application that has 3 view controllers. The root view controller is an item listing, basic table view. Off of this view controller, I push two different view controllers based on some user interaction - a create item view controller or a view item view controller.

                所以,情节提要的转场看起来就像一个 V 或其他东西.

                So, the storyboard segues just look like a V, or something.

                在我的 create item 视图控制器上,我希望它在用户创建新项目时弹回根视图控制器,然后推送到 view item 控制器,以便我可以查看新创建的项目.

                On my create item view controller, I would like it to pop back to the root view controller when the user creates a new item, but then push to the view item controller so that I can look at the newly created item.

                我似乎无法让它工作.弹回根视图控制器很容易,但我无法推送该 view item 控制器.

                I can't seem to get this to work. It's easy enough to pop back to the root view controller, but I'm unable to push that view item controller.

                有什么想法吗?我在下面粘贴了我的代码.pop 功能有效,但新视图永远不会出现.

                Any ideas? I've pasted my code, below. The pop function works, but the new view never appears.

                - (void) onSave:(id)sender {
                
                    CLLocation *currentLocation = [[LocationHelper sharedInstance] currentLocation];
                
                    // format the thread object dictionary
                    NSArray* location = @[ @(currentLocation.coordinate.latitude), @(currentLocation.coordinate.longitude) ];
                    NSDictionary* thread = @{ @"title": _titleField.text, @"text": _textField.text, @"author": @"mustached-bear", @"location": location };
                
                    // send the new thread to the api server
                    [[DerpHipsterAPIClient sharedClient] postPath:@"/api/thread"
                                                       parameters:thread
                                                          success:^(AFHTTPRequestOperation *operation, id responseObject) {
                
                                                              // init thread object
                                                              Thread *thread = [[Thread alloc] initWithDictionary:responseObject];
                
                                                              // init view thread controller
                                                              ThreadViewController *viewThreadController = [[ThreadViewController alloc] init];
                                                              viewThreadController.thread = thread;
                
                                                              [self.navigationController popToRootViewControllerAnimated:NO];
                                                              [self.navigationController pushViewController:viewThreadController animated:YES];
                
                                                          }
                                                          failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                
                                                              [self.navigationController popToRootViewControllerAnimated:YES];
                
                                                          }];
                
                }
                

                推荐答案

                完成你想做的事情的一个简单方法是在你的主根视图控制器中构建一些简单的逻辑 -(void)viewWillAppear 方法并使用委托回调翻转逻辑开关.基本上是对根控制器的反向引用".这是一个简单的例子.

                An easy way to accomplish what you want to do is to build some simple logic into your main root view controllers -(void)viewWillAppear method and use a delegate callback to flip the logic switch. basically a "back reference" to the root controller. here is a quick example.

                主根控制器(考虑这个控制器a) - 称之为controllerA设置一个属性来跟踪跳转状态

                main root controller (consider this controller a) - well call it controllerA set a property to keep track of the jump status

                @property (nonatomic) BOOL jumpNeeded;
                

                - (void)viewWillAppear:(BOOL)animated {
                    [super viewWillAppear:animated];
                    self.jumpNeeded ? NSLog(@"jump needed") : NSLog(@"no jump needed");
                
                    if (self.jumpNeeded) {
                        NSLog(@"jumping");
                        self.jumpNeeded = NO;
                        [self performSegueWithIdentifier:@"controllerC" sender:self];
                    }   
                }
                

                现在,在主根控制器中,选择TableView行时,请执行此操作在您的 tableView 中推送到 controllerB 时确实选择了方法

                Now, in your main root controller,when a tableview row is selected do something like this when pushing to controllerB in your tableView did select method

                [self performSegueWithIdentifer@"controllerB" sender:self];
                

                然后实现你的准备 segue 方法

                then implement your prepare for segue method

                - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
                
                  //setup controller B
                  if([segue.identifier isEqualTo:@"controllerB"]){
                    ControllerB *b = segue.destinationViewController;
                    b.delegate = self;  //note this is the back reference
                  }
                
                  //implement controller c here if needed
                }
                

                现在转到控制器 B您需要设置一个名为delegate"的属性来保存反向引用并且需要从根控制器导入头文件

                Now move on to controllerB you need to set a property called "delegate" to hold the back reference and you need to import the header file from the root controller

                #import "controllerA"
                
                @property (nonatomic,weak) controllerA *delegate;
                

                然后在您弹回控制器A之前,设置标志

                then just before you pop back to controllerA, you set the flag

                   self.delegate.jumpNeeded = YES;
                    [self.navigationController popViewControllerAnimated:YES];
                

                就是这样.您不必对控制器C 做任何事情.还有其他一些方法可以做,但这对于您的需求来说非常简单.希望它对你有用.

                and that is about it. You don't have to do anything with controllerC. There are a few other ways to do, but this is pretty straight forward for your needs. hope it works out for you.

                这篇关于如何弹回根视图控制器,然后推送到不同的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Android UINavigationController-like 功能 下一篇:与两个 UINavigationController 共享与 rootViewController 相同的 UIView

                相关文章

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

                <tfoot id='ZBwBe'></tfoot>
              • <small id='ZBwBe'></small><noframes id='ZBwBe'>

                <legend id='ZBwBe'><style id='ZBwBe'><dir id='ZBwBe'><q id='ZBwBe'></q></dir></style></legend>