[英]How to pop all view and go back to login view when user tap logout button
I use a navigation controller for login view.From there i push to a tabbar controller using this code 我将导航控制器用于登录视图。从那里我使用此代码推送到标签栏控制器
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:@"tab"];
self.navigationController.navigationBarHidden=YES;
[self.navigationController pushViewController:obj animated:YES];
How can navigate back to login view when user tap logout from profile screen (one of the tabbar controller view). 当用户从配置文件屏幕中点击注销时,如何导航回到登录视图(选项卡控制器视图之一)。 I want a navigation bar in the login view.
我需要登录视图中的导航栏。 Can anyone please help.
谁能帮忙。 I am using Storyboard.
我正在使用情节提要。
You could use the following :- 您可以使用以下内容:
//This would pop to the given VC
[self.navigationController popToViewController:loginViewController animated:YES];
//This would pop to the root VC
[self.navigationController popToRootViewControllerAnimated:YES]
Update:- 更新:-
- (IBAction)loginBtn{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
//U provided UITabBarController so replace at with your tabBar controller class like below ,TabViewController class is created.
TabViewController *obj=[storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
self.navigationController.navigationBarHidden=YES; //navigation bar hidden so won't appear when back again to login if want to see then make it true in viewWillAppear/viewWillLoad.
[self.navigationController pushViewController:obj animated:YES];
}
Also for coming back from tabBar to login VC follow below, 同样,为了从tabBar返回以登录VC,请按照以下步骤操作:
- (IBAction)popbtn:(id)sender{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Also assgin the class to tabBar controller in storyboard along with storyboard id as below:- 还将类与情节提要ID关联到情节提要中的tabBar控制器,如下所示:-
Try this: 尝试这个:
[[self.parentViewController navigationController] popToRootViewControllerAnimated:YES];
Since you are pushing a TabBarController
, you will need to pop using the TabBarController. 由于您正在推动
TabBarController
,因此需要使用TabBarController弹出。 self.parentViewController
should give you the TabBarController. self.parentViewController
应该给你TabBarController。
您只能使用一行代码。
[self.navigationController pushViewController:viewController animated:YES];
id rootController = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
if([rootController isKindOfClass:[LoginViewController class]]){
//do something
[self.navigationController popToRootViewControllerAnimated:YES];
}
else{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"login"];
[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.