ios 在关闭前一个视图控制器后立即呈现视图控制器 [英] ios present view controller immediately after dismissing a previous one
问题描述
在我的 ios 应用程序中,假设我有三个 ViewController
:A
、B
和 C
.
In my ios app lets say I have three ViewControllers
: A
, B
, and C
.
从 A
我提出 B
并指定 A
作为代表.在 B
上完成操作后,我想关闭 B
并从 A
呈现 C
.但是,我想在屏幕上根本不显示 A
的情况下执行此操作.这是我现在的代码,在 A
类中:
From A
I present B
and assign A
as a delegate. After an action is done on B
I want to then dismiss B
and present C
from A
. However, I want to do this without A
showing up on the screen at all. This is my code right now, inside class A
:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
B *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"B-identifier"];
vc.delegate = self;
[self presentViewController:vc animated:NO completion:^{}];
}
然后这是A
内部的委托函数,B
在执行动作时调用:
Then this is the delegate function inside A
that B
calls when the action is performed:
- (void) actionPerformed
{
[self dismissViewControllerAnimated:YES completion:^{
C *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"C"];
[self presentViewController:vc animated:NO completion:nil];
}];
然而,这会导致 C 出现一点(在调用解雇之后),即使我将呈现代码放在解雇的完成处理程序中.我该怎么做才能避免这种情况?
However this causes C to show up for a bit (after calling dismiss) even though I put the presenting code in the completion handler of the dismissal. What can I do to avoid that?
推荐答案
如果您将其用于登录方法,那么您应该尝试不同的方法.我的意思是如果 A 是您的 rootViewController(使其成为登录视图控制器),它会检查用户是否有会话.假设用户有一个会话,然后使用 [[[[UIApplication sharedApplication] delegate] window]setRootViewController:]
将您的 C viewController 设为 rootViewController,如果他没有会话,则向他显示相同的页面(A viewController) 不需要 B.尝试一下可能会提高您的应用性能.
If you are using it for login approach then you should try a different approach. I mean if A is your rootViewController(make it as login view controller) which check if user has a session or not. suppose user has a session then make your C viewController as rootViewController using [[[[UIApplication sharedApplication] delegate] window]setRootViewController:]
and if he does not has a session show him the same page (A viewController) there is no need of B. Just try it may be it will improve your app performance.
这篇关于ios 在关闭前一个视图控制器后立即呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!