关闭并呈现相同的视图控制器
Dismiss and Present same view controller
我有一个视图控制器,我需要关闭它并同时返回它。
我曾尝试关闭它并回调视图控制器但没有工作。
[self dismissViewControllerAnimated:YES completion:nil];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
ExpandViewController *expandView=
[storyboard instantiateViewControllerWithIdentifier:@"ExpandViewController"];
expandView.delegate=self;
[expandView setEventDict:dict];
[self presentViewController:expandView animated:YES completion:NULL];
在当前呈现的视图控制器完成关闭之前,您无法呈现视图控制器。在调用解雇的 completion
处理程序之前,您不会知道这已经发生。您的错误是 completion
处理程序是 nil
。相反,提供一个 completion
处理程序(在您的第一行中),由您的代码的其余行组成。因此,他们将在 解雇完成后执行 。
[self dismissViewControllerAnimated:YES completion:^{
// ... the rest of your code goes in here ...
}];
我不确定 outcome/functionality 您在问题中寻找的是什么,但@matt 是正确的。但是,您可能希望无缝地实现这一点。因此,您可以使用 child 视图控制器,而不是使用 [self presentViewController:VC animated:animate completion:nil]
方法呈现视图控制器。
添加childvc:
[self addChildViewController:myVC];
[self.view addSubview:myVC.view];
[myVC didMoveToParentViewController:self];
删除 child vc:
[myVC willMoveToParentViewController:nil];
... remove subview.
您可以在两个控制器之间设置一个委托,以告知 parent 何时关闭视图以简化操作。您还可以使用 [self.view insertSubview:myVC atIndex:index]
或其他可能的功能(例如在子视图上方插入等)在不同索引处添加子视图,以便在关闭另一个子视图之前添加一个子视图以提供更无缝的过渡。
希望对您有所帮助!
我有一个视图控制器,我需要关闭它并同时返回它。 我曾尝试关闭它并回调视图控制器但没有工作。
[self dismissViewControllerAnimated:YES completion:nil];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
ExpandViewController *expandView=
[storyboard instantiateViewControllerWithIdentifier:@"ExpandViewController"];
expandView.delegate=self;
[expandView setEventDict:dict];
[self presentViewController:expandView animated:YES completion:NULL];
在当前呈现的视图控制器完成关闭之前,您无法呈现视图控制器。在调用解雇的 completion
处理程序之前,您不会知道这已经发生。您的错误是 completion
处理程序是 nil
。相反,提供一个 completion
处理程序(在您的第一行中),由您的代码的其余行组成。因此,他们将在 解雇完成后执行 。
[self dismissViewControllerAnimated:YES completion:^{
// ... the rest of your code goes in here ...
}];
我不确定 outcome/functionality 您在问题中寻找的是什么,但@matt 是正确的。但是,您可能希望无缝地实现这一点。因此,您可以使用 child 视图控制器,而不是使用 [self presentViewController:VC animated:animate completion:nil]
方法呈现视图控制器。
添加childvc:
[self addChildViewController:myVC];
[self.view addSubview:myVC.view];
[myVC didMoveToParentViewController:self];
删除 child vc:
[myVC willMoveToParentViewController:nil];
... remove subview.
您可以在两个控制器之间设置一个委托,以告知 parent 何时关闭视图以简化操作。您还可以使用 [self.view insertSubview:myVC atIndex:index]
或其他可能的功能(例如在子视图上方插入等)在不同索引处添加子视图,以便在关闭另一个子视图之前添加一个子视图以提供更无缝的过渡。
希望对您有所帮助!