简体   繁体   English

DismissViewController解雇两个UIViewControllers

[英]DismissViewController dismissing two UIViewControllers

I´m presenting a view this way: 我这样呈现一个视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ContractDetailsViewController *contractDetailsViewController = [[ContractDetailsViewController alloc] init];
    contractDetailsViewController.client = self.client;
    contractDetailsViewController.contractId = [NSString stringWithFormat:@"%d", indexPath.row];

    [self presentViewController:[[UINavigationController alloc]initWithRootViewController:contractDetailsViewController] animated:YES completion:^{
    }];
}

After the view appears i dismiss it with: 视图出现后我将其解雇:

- (void)close
{
    [self dismissViewControllerAnimated:YES completion:^{}];
}

The bug is that the view disappears, the view that was behind it also disappears right after. 错误是视图消失,它背后的视图也随之消失。

This could explain what is happening to your view controllers: 这可以解释视图控制器发生的情况:

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. 如果连续呈现多个视图控制器,从而构建一堆呈现的视图控制器,则在堆栈中较低的视图控制器上调用此方法会解除其直接子视图控制器以及堆栈上该子视图上方的所有视图控制器。 When this happens, only the top-most view is dismissed in an animated fashion; 发生这种情况时,只有最顶层的视图以动画方式被删除; any intermediate view controllers are simply removed from the stack. 任何中间视图控制器都可以从堆栈中删除。 The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack. 最顶层的视图使用其模态过渡样式被忽略,这可能与堆栈中较低的其他视图控制器使用的样式不同。

( source ) 来源

This means that if you present view controller A, then view controller B, then call dismiss on view controller B, both view controllers are dismissed (although only B with an animation). 这意味着如果您呈现视图控制器A,然后查看控制器B,然后在视图控制器B上调用dismiss,则两个视图控制器都被关闭(尽管只有B带有动画)。

If you want to manage two different hierarchies of view controllers, you could use a second navigation controller. 如果要管理两个不同的视图控制器层次结构,可以使用第二个导航控制器。 That means, eg, that you would present a new navigation controller instead of view controller A, and make view controller A the navigation controller's root controller. 这意味着,例如,您将呈现新的导航控制器而不是视图控制器A,并使视图控制器A成为导航控制器的根控制器。 Then you would push/pop any other required view controller (B, etc.) 然后你会推/弹任何其他所需的视图控制器(B等)

As per apple documentation. 根据苹果文档。

If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. 如果连续呈现多个视图控制器,从而构建一堆呈现的视图控制器,则在堆栈中较低的视图控制器上调用此方法会解除其直接子视图控制器和堆栈上该子视图上方的所有视图控制器。 When this happens, only the top-most view is dismissed in an animated fashion; 发生这种情况时,只有最顶层的视图以动画方式被删除; any intermediate view controllers are simply removed from the stack. 任何中间视图控制器都可以从堆栈中删除。 The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack. 最顶层的视图使用其模态过渡样式被忽略,这可能与堆栈中较低的其他视图控制器使用的样式不同。

If you want to achieve that functionality, just add UIViews in current view and show them in modal way. 如果要实现该功能,只需在当前视图中添加UIViews并以模态方式显示它们。 You can remove them one by one. 您可以逐个删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM