【问题标题】:Calling popToRootViewControllerAnimated after dismissModalViewControllerAnimated在dismissModalViewControllerAnimated 后调用popToRootViewControllerAnimated
【发布时间】:2010-10-04 04:57:54
【问题描述】:

我正在工作的应用程序中调用presentModalViewController,一旦完成(调用dismissModalViewControllerAnimated:YES),它应该立即调用popToRootViewControllerAnimated

但问题是 dismissModalViewControllerAnimated:YES 工作正常,但 popToRootViewControllerAnimated 在它之后无法工作。

代码如下:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];

【问题讨论】:

    标签: ios objective-c navigationcontroller


    【解决方案1】:

    试试这样的:

    [self.navigationController dismissModalViewControllerAnimated:YES] ;
    [self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3];
    
    
    -(void)patchSelector{
      [self.navigationController popToRootViewControllerAnimated:YES]; 
    }
    

    它不是那么整洁,但它应该可以工作。

    更新: 你应该使用

     [self dismissModalViewControllerAnimated:YES];
    

    改为

     [self.navigationController dismissModalViewControllerAnimated:YES] ;
    

    呈现模式的对象是视图控制器,而不是导航控制器。

    【讨论】:

      【解决方案2】:

      如果你有一个带有 UIViewController 堆栈的导航控制器:

      [self dismissModalViewControllerAnimated:YES];
      [(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES];
      //UIViewController *vc = [[UIViewController new] autorelease];
      //[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES];
      

      假设调用模态视图控制器的视图控制器具有navigationController。

      【讨论】:

        【解决方案3】:

        我猜,你没有调用

        [self.navigationController popToRootViewControllerAnimated:YES];
        

        在目标模态视图控制器中。检查一下。

        【讨论】:

          【解决方案4】:

          我遇到了类似的事情。你需要先复制你的self.navigationcontroller,同时也保留你自己,所以当你调用第二个pop时,仍然有对NC的引用,你仍然存在。

              // locally store the navigation controller since
              // self.navigationController will be nil once we are popped
          UINavigationController *navController = self.navigationController;
          
              // retain ourselves so that the controller will still exist once it's popped off
          [[self retain] autorelease];
          
              // Pop this controller and replace with another
          [navController popViewControllerAnimated:NO];
          [navController pushViewController:someViewController animated:NO];
          

          见:How can I pop a view from a UINavigationController and replace it with another in one operation?

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-01-20
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多