iPhone - 为不同类型的视图/窗口设置应用程序导航的正确方法是什么?

发布于 2024-11-01 20:42:37 字数 440 浏览 4 评论 0原文

作为 Objective-C 和 IOS 的新手,我发现最难理解的事情之一是如何加载新视图以及如何在应用程序的各个阶段向用户显示的内容之间移动。

我首先创建一个应用程序,其底部有一个选项卡栏控制器,顶部有一个导航栏,我已经掌握了这一点以及如何为每个选项卡栏项目加载不同的视图。

但是我想扩展应用程序,以便发生以下情况,

用户加载应用程序,首先出现一个简单的登录屏幕,如果用户输入正确的详细信息,如果输入不正确,应用程序将移动到我当前的选项卡栏和导航栏设置详细信息他们会转到一个简单的错误页面。

所以我不确定我需要在我的应用程序中更改什么才能实现此目的,我是否需要创建一个新窗口并在其中放置一个用于登录屏幕的视图,然后如何加载当前设置?

我是否要将主界面更改为新窗口?或者我是否必须更改当前的 MainWindow.xib 以加载登录视图,然后在不同的 xib 文件中重新创建当前的设置?

As a newcomer to objective-c and IOS one of the hardest things I've found to get my head around is how to load new views and move between what I want to display to the user at various stages of the application.

I have started by creating an app with a Tab Bar controller at the bottom and a navigation bar at the top, I have grasped this and how to load different views for each tab bar item.

However I want to expand the app so the following happens,

The user loads the app, first off a plain login screen appears, if the user enters correct details the app moves to my current setup of the tab bar and navigation bar if they enter incorrect details they go to a plain error page.

So I'm not sure what I need to change in my app to achieve this, do I need to create a new window and put a view in it for the login screen and then how do I load my current setup?

Do I change my Main Interface to a new window? Or do I have to change my current MainWindow.xib to load the login view and then re create my current setup in a different xib file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-11-08 20:42:37

您可能已经知道,视图通常由 UIViewController 的相应子类管理。他们可以以多种方式呈现视图,例如模态(新视图向上滑动并覆盖前一个视图)、在 UITabBarController 的选项卡中或作为带有 UINavigationController 的导航层级的一部分。
关于您的情况,我建议加载标准选项卡栏控制器并让它以模态方式呈现您的登录视图。当用户按下登录按钮时,模态视图将消失并向下滑动以显示选项卡栏控制器中的实际内容:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    LoginViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentModalViewController:loginViewController animated:NO];
    [loginViewController release];

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
}

然后必须调用 LoginViewController 中的登录按钮:

- (void)loginSuccessful {
    [self.parentViewController dismissModalViewController];
}

此解决方案使登录屏幕覆盖选项卡栏控制器视图该应用程序启动,并在用户登录后滑出屏幕。

As you may already know, views are usually managed by corresponding subclasses of UIViewController. They can present their views in multiple ways, e.g. modal (the new view slides up and covers the previous view), in a tab of a UITabBarController or as part of a navigational hirachy with a UINavigationController.
Concerning your case, I recommend loading your standard tab bar controller and let it present your login view modally. When the user presses the login button, the modal view gets dismissed and slides down to show the actual content in the tab bar controller:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    LoginViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentModalViewController:loginViewController animated:NO];
    [loginViewController release];

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
}

The Login Button in the LoginViewController must then call:

- (void)loginSuccessful {
    [self.parentViewController dismissModalViewController];
}

This solution makes the login screen cover the tab bar controller view when the app launches and will make it slide down out of the screen when the user has logged in.

绅士风度i 2024-11-08 20:42:37

通常我们在 iPhone SDK 中只能使用一个 UIWindow。所以我们必须通过一个 UIWindow 来处理所有事情。您可以在 AppDelegate.m 文件中使用以下代码。当用户单击登录按钮时,您可以删除登录页面并显示选项卡栏控制器

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

// Override point for customization after app launch    
     [window addSubview:viewController.view];// you log in page
     [window addSubview:tabController.view];//Your Tab bar controller
[window makeKeyAndVisible];

}

-(IBAction)Login_buttonClicking
{
[viewController.view removeFromSuperview];
}

Usually We can use one UIWindow only in iPhone SDK.So We have to handle all things through one UIWindow.You can use the following code in your AppDelegate.m file.When user clicks login button, you can remove login page and show Tab bar controller

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

// Override point for customization after app launch    
     [window addSubview:viewController.view];// you log in page
     [window addSubview:tabController.view];//Your Tab bar controller
[window makeKeyAndVisible];

}

-(IBAction)Login_buttonClicking
{
[viewController.view removeFromSuperview];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文