如何点击登录按钮进入首页
- (IBAction)loginClick:(id)sender {
HomeVC *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"home"];
[self.navigationController pushViewController:secondView animated:YES];
self.tabBarController.selectedIndex = 1;
}
最佳答案
首先,您必须将登录页面设置为根 Controller ,当您成功登录后,您必须更改根 Controller 并将选项卡栏设置为根 Controller 。 在您的 AppDelegate 中执行此代码,并在您的登录和注销页面上调用这些方法。
@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,readonly) UITabBar *tabBar;
@property(nonatomic,strong) UITabBarController *tabBarController;
- (void)Login{
[self.window setRootViewController:nil];
UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
UITabBarController *bar= (UITabBarController*)[MainStoryboard instantiateViewControllerWithIdentifier:@"tabbar"];
self.window.rootViewController=bar;
}
-(void)Logout
{
// self.window.rootViewController = nil;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UINavigationController*vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"homepage"];
// Homepage *controller = [[Homepage alloc] initWithDelegate:self];
self.window.rootViewController = vc;
}
关于ios - 单击相应的 UIButton 后如何转到 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27773580/