开始新项目时仍然感到困惑。我有一个选项卡栏应用程序,其中包含许多选项卡以及与每个选项卡关联的导航 Controller 。
我需要在标签栏之前添加一个登录屏幕。还需要在用户登录一次时将用户带到标签栏。即,一旦用户登录,每次他被定向到标签栏,除非他注销。我需要选择一种模式。
然后 [window addSubview:loginviewcontroller.view] 并在用户成功登录时隐藏 loginviewcontroller
请选择我最好的选择或任何其他方式来做得更好。
最佳答案
**Changing the window.rootViewController to the tabbarcontroller
when the user signs in and if not set the window.rootview controller
as the login view controller.**
是做这件事的最好方法,
最初,如果用户未登录,则 LoginViewController 将是 RootViewController,否则 tabBarController 将是 RootViewController,并且当用户注销时,将 RootViewController 更改为 LoginViewController。
更新:试试这个,这会奏效。如果不清楚,请告诉我,我将向您发送一个工作项目。
Bydefault InitialViewController from your Main Storyboard is instantiated and displayed automatically when your app starts up. To prevent this happening you need to remove the UIMainStoryboardFile setting from your info.plist file.
With no default view controller, you are now free to create one programmatically at app start.
在这里,我在这一行下面写了一个小例子。创建两个没有 xib FirstViewController 和 SecondViewController 的 View Controller ,并在 MainStoryboard_iPhone 和 Appdelegate.m 中添加比实现这些方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/*
call any of the two methods below, it will change the RootViewController accordingly
*/
// [self firstRootViewController]; // make FirstViewController Root view controller
[self secondRootViewController]; // make SecondViewController Root view controller
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void) firstRootViewController {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
FirstViewController *first = [sb instantiateViewControllerWithIdentifier:@"FirstViewController"];
[self.window setRootViewController:first];
}
- (void) secondRootViewController {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
SecondViewController *second = [sb instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.window setRootViewController:second];
}
现在在 MainStoryboard_iPhone.storyboard 中设置 viewController
关于ios - 基于 iOS 应用程序设计 View Hierarchy Tabbar bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19566157/