Iphone 将ViewController放置在Tabbar控制器的顶部
基本上,在我显示Tabbar控制器之前,我想在我的iPhone应用程序中创建一个登录屏幕。我尝试了以下方法,首先在窗口子视图中添加TabBarController,然后在顶部添加LoginViewController。我做错了什么,还是应该完全不同Iphone 将ViewController放置在Tabbar控制器的顶部,iphone,objective-c,ios,uiviewcontroller,uitabbarcontroller,Iphone,Objective C,Ios,Uiviewcontroller,Uitabbarcontroller,基本上,在我显示Tabbar控制器之前,我想在我的iPhone应用程序中创建一个登录屏幕。我尝试了以下方法,首先在窗口子视图中添加TabBarController,然后在顶部添加LoginViewController。我做错了什么,还是应该完全不同 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Ove
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = @"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = @"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.window addSubview:lvc_nc.view];
[lvc release];
[lvc_nc release];
return YES;
}
我会使用两种不同的观点。一个将处理登录过程,另一个是提供应用程序功能的“登录视图”。当应用程序启动时,您可以添加登录视图,检查用户名/密码,当登录正常时,您可以切换到第二个视图。我将使用两种不同的视图。一个将处理登录过程,另一个是提供应用程序功能的“登录视图”。当应用程序启动时,您可以添加登录视图,检查用户名/密码,登录正常后,您可以切换到第二个视图。您是否有适用于my Tabbar Controller的代码示例?不,抱歉,我正在工作,无法提供代码示例:/From the logic:只需创建两个不同的UIViewController,其中一个包含您的登录表单,并在您的ApplicationIDFinishLaunching方法中显示/添加get。在其中放置一个方法,验证输入的用户凭据,并在用户名/密码正确的情况下显示第二个视图(保存UITabBar)。是否有适用于my tabbarcontroller的代码示例?不,抱歉,我正在工作,无法提供代码示例:/From the logic:只需创建两个不同的UIViewController,其中一个包含您的登录表单,并在您的ApplicationIDFinishLaunching方法中显示/添加get。如果用户名/密码正确,则在其中放入一个方法,以验证输入的用户凭据并显示第二个视图(保存UITabBar)。我昨天遇到了相同的问题,@rckoenes编写的
presentModalViewController
是正确且有效的解决方案。哈,似乎太有效了!这是在我完成LoginView后删除它的正确方法吗?[self.parentViewController dismissModalViewControllerAnimated:是]<代码>[自我解除ModalViewController激活:是]会很好。我昨天遇到了同样的问题,presentModalViewController
正如@rckoenes所写的是正确且有效的解决方案哈,似乎太有效了!这是在我完成LoginView后删除它的正确方法吗?[self.parentViewController dismissModalViewControllerAnimated:是]<代码>[自我解除ModalViewController激活:是]代码>就可以了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = @"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = @"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.tabController presentModalViewController:lvc_nc animated:no];
[lvc release];
[lvc_nc release];
return YES;
}