问题描述
简而言之:如何从Presented ViewController中使用PushViewController?
In Short :How can I PushViewController from Presented ViewController ?
简介:
我有MainViewController
,其中单击一个按钮,其中有一个名为LoginViewController
的视图.
I have MainViewController
, In which I have one button on click of button, I am presenting a view called LoginViewController
.
在此页面(LoginViewController
)上,我再次显示button
,单击此按钮后,我尝试将其不推动的视图控制器(称为HomeViewController
)推入.
On this page (LoginViewController
), I again have button
, on click of that, I try to push my view controller(called HomeViewController
) it doesn't pushes.
这是我的代码段,
MainViewController.m
- (IBAction)LoginClicked:(id)sender {
LoginViewController *vc = [[LoginViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
}
LoginViewController.m
- (IBAction)buttonActionMethodOnLoginView:(id)sender{
NSLog(@"viewControllers %@",APPDELEGATE.nav.viewControllers);
//LoginViewController is not in this array
HomeViewController *obj = [[HomeViewController alloc] init];
[self.navigationController pushViewController:obj animated:YES];
}
但这对我不起作用.另外,我在pushed
之前打印了a stack of view controllers
,但是它没有LoginViewController
.因此,在不将LoginViewController
添加到a stack of view controllers
的情况下,如何将pushed
从LoginViewController
转换为HomeViewController
?
But it did not works for me. Also, I printed a stack of view controllers
before pushed
, but it doesn't have LoginViewController
. So, without adding LoginViewController
into a stack of view controllers
, How can I pushed
to HomeViewController
from LoginViewController
?
当我从HomeViewController
处回来时,应该打开LoginViewController
.
When I getBack from HomeViewController
, then LoginViewController
should get opened..
是否可以使用此单个NavigationController
?
注意:-在这里,我以使用Login,Home和Main ViewController为例.但我希望将其导入其他屏幕.
Note:- Here, I have just taken an example using Login, Home and Main ViewController. But I want that into Other Screens.
推荐答案
您必须从firstView(MainViewController
)中开始Push
,但是您可以使用与PresentView
和DismissView
相同的动画.为此使用以下代码:-
You have to Push
from your firstView (MainViewController
), but you can use animation same as PresentView
and DismissView
. Use following code for this :-
用于推送(在MainViewController
上)
LoginViewController *VC = [[LoginViewController alloc]init];
CATransition* transition = [CATransition animation];
transition.duration = 0.3f;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[[[UINavigationController alloc] initWithRootViewController:VC] pushViewController:VC animated:NO];
//[self.navigationController pushViewController:VC animated:NO];
用于流行音乐(在LoginViewController
上)
CATransition* transition = [CATransition animation];
transition.duration = 0.3f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
使用此代码,您可以获得与Present-Dismiss ViewControllers
相同的动画.有关更多详细信息,请参考此答案.
Using this code, you can get animation same as Present-Dismiss ViewControllers
. Refer this answer for more details.
然后,您可以将代码用于Pushing
LoginViewController
至HomeViewController
And after that, you can use your code for Pushing
LoginViewController
to HomeViewController
希望,这就是您想要的.如有任何疑问,请联系我. :)
Hope, this is what you're looking for. Any concern get back to me. :)
这篇关于从iOS中的Presented View Controller推送视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!