Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从普通视图切换到选项卡栏控制器_Iphone_Views_Uitabbarcontroller_Switching - Fatal编程技术网

Iphone 从普通视图切换到选项卡栏控制器

Iphone 从普通视图切换到选项卡栏控制器,iphone,views,uitabbarcontroller,switching,Iphone,Views,Uitabbarcontroller,Switching,我构建了我的第一个iPhone应用程序,但在切换视图时遇到了问题。 首先,我有两个视图(登录、注册),通过“presentModalViewController:animated:”切换 但是如果有人登录,肯定会有一种新的视图。我想在底部有一个UITabBar(选项卡栏控制器)。但这是行不通的。我尝试创建一个新的AppDelegate,这样我就可以使用需要AppDelegate的教程: 切换到新控制器的操作如下: startViewController = [[StartViewControl

我构建了我的第一个iPhone应用程序,但在切换视图时遇到了问题。 首先,我有两个视图(登录、注册),通过“presentModalViewController:animated:”切换

但是如果有人登录,肯定会有一种新的视图。我想在底部有一个UITabBar(选项卡栏控制器)。但这是行不通的。我尝试创建一个新的AppDelegate,这样我就可以使用需要AppDelegate的教程:

切换到新控制器的操作如下:

startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil];
[UIView beginAnimations:@"View Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:startViewController.view];
[UIView commitAnimations];
屏幕为白色,因为显示的视图是my StartView.xib中的UIView。在这里,我有了新的AppDelegate、文件的所有者、视图和控制器。但只加载UIView,而不加载TabBarController

你知道我如何解决这个问题吗


谢谢并致以最良好的问候。

我可能建议您从Tabbar控制器开始,如果未设置用户名/密码,则活动的ViewController将执行presentModalViewController:animated:以模态模式显示登录/注册ViewsController(隐藏底层Tabbar控制器)

下面是一些以编程方式执行此操作的示例代码

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 [window setBackgroundColor:[UIColor whiteColor]];

 tabBarController = [[UITabBarController alloc] init];


 aViewController = [[aViewController alloc] init];
 UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
 aNavController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 [aViewController release];

 tabBarController.viewControllers = [NSArray arrayWithObjects: aNavController, nil];

 // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];

 if(userNotLoggedIn){
     [self displayLoginViewController];
 }


    [window makeKeyAndVisible];
}

- (void)displayLoginViewController {
 LoginViewController *controller = [[LoginViewController alloc] init];
 // setup controller
 [self.tabBarController presentModalViewController:controller animated:NO];
 [controller release];
}

我可能建议您从TabBarController开始,如果未设置用户名/密码,则活动的ViewController将执行presentModalViewController:animated:以模态模式显示登录/注册ViewsController(隐藏底层TabBarController)

下面是一些以编程方式执行此操作的示例代码

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 [window setBackgroundColor:[UIColor whiteColor]];

 tabBarController = [[UITabBarController alloc] init];


 aViewController = [[aViewController alloc] init];
 UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
 aNavController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 [aViewController release];

 tabBarController.viewControllers = [NSArray arrayWithObjects: aNavController, nil];

 // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];

 if(userNotLoggedIn){
     [self displayLoginViewController];
 }


    [window makeKeyAndVisible];
}

- (void)displayLoginViewController {
 LoginViewController *controller = [[LoginViewController alloc] init];
 // setup controller
 [self.tabBarController presentModalViewController:controller animated:NO];
 [controller release];
}

非常感谢您的回复。对不起,我不知道你的确切意思。我应该在MainWindow.xib中创建一个TabBarController。因此,如果我启动应用程序,底部的选项卡栏将显示,而不是我的登录视图或注册视图?!确切地说,当应用程序启动时,将加载TabBarController,并从TabBarController中包含的firstViewController检查用户名/密码是否正确,如果未设置,则执行presentModalViewController以显示loginViewController,它应该是如此之快,以至于几乎看不到TabbarControlWe产生您所需的效果。是的,但是,如果应用程序启动,将显示登录屏幕。用户必须首先登录,因此第一个屏幕始终是登录屏幕。如果有人成功登录,我需要切换它。在模式模式下启动应用程序(在TabBarController顶部)后,登录屏幕将立即按下。因此,当用户打开应用程序且其未登录时,他必须登录或注册,如果他已经登录/注册,则不会显示modalViewcontroller,他将只看到TabBarController。用户必须始终登录!应用程序启动时,他从未登录过。我不明白如何从登录视图切换到TabBarController视图。非常感谢您的回复。对不起,我不知道你的确切意思。我应该在MainWindow.xib中创建一个TabBarController。因此,如果我启动应用程序,底部的选项卡栏将显示,而不是我的登录视图或注册视图?!确切地说,当应用程序启动时,将加载TabBarController,并从TabBarController中包含的firstViewController检查用户名/密码是否正确,如果未设置,则执行presentModalViewController以显示loginViewController,它应该是如此之快,以至于几乎看不到TabbarControlWe产生您所需的效果。是的,但是,如果应用程序启动,将显示登录屏幕。用户必须首先登录,因此第一个屏幕始终是登录屏幕。如果有人成功登录,我需要切换它。在模式模式下启动应用程序(在TabBarController顶部)后,登录屏幕将立即按下。因此,当用户打开应用程序且其未登录时,他必须登录或注册,如果他已经登录/注册,则不会显示modalViewcontroller,他将只看到TabBarController。用户必须始终登录!应用程序启动时,他从未登录过。我不明白如何从login视图切换到TabBarController视图。