在 iOS 中构建多视图应用程序有什么首选方法吗?

发布于 2025-01-01 09:17:27 字数 686 浏览 1 评论 0原文

简短介绍

我是使用 iOS 平台进行应用程序开发领域的新手。目前我需要为 iPhone 和 iPad 开发多视图应用程序。

我的研究

我一直在对多视图应用程序的开发进行一些研究,发现一般方法是使用提供的控制器之一作为根视图控制器(UI 选项卡栏控制器等)在)。或者,或者编写自己的根视图控制器。

我的问题

我现在遇到的具体问题主要是如何构建一个更复杂的应用程序,其中包括:

- 登录视图(这是呈现给用户的第一个视图)打开应用程序后) -应用程序的其余部分应该使用 UI 选项卡栏控制器进行导航)

我现在想到的是这个想法:

创建一个自定义根视图控制器。该根视图控制器将首先向用户呈现登录视图(通过将登录视图添加为其自身的子视图)。登录后,应该将子视图更改为UI选项卡栏控制器。

实际问题

那么我的问题是这是否是一种可以接受的方法?基本上我会有一个根视图控制器,它通过将这些视图添加为其自身的子视图来在视图之间切换。

我还没有真正找到任何讨论可接受的方法的文章。我对当前想法的担忧是,拥有一个基本上包含应用程序的所有视图并在它们之间切换的主根视图控制器可能很快就会变得混乱?

任何意见都会被采纳:)

提前致谢。

Short Introduction

I am kind of new in the field of app development using the iOS platform. Currently I'm in need of developing a multiview application for iPhone as well as iPad.

My Research

I've been doing some research on development of multiview applications, and have found that the general approach is to use one of the provided controllers as a root view controller (the UI tab bar controller and so on). Either that, or to write your own root view controller.

My Problem

The specific problem I'm battling right now is mostly concerning how to build up a more complex application which consists of:

-A log-in view (this is the very first view presented to the user upon opening the app)
-The rest of the application which should be navigated using an UI tab bar controller)

What I've come up with right now is this idea:

Create a custom root view controller. This root view controller will first present the log-in view to the user (by adding the log-in view as a subview of itself). After log-in, it should change the subview to the UI tab bar controller.

The actual question

My question then is if this is an acceptable approach of doing it? Basically I would have a root view controller which switches between views by adding those views as subviews of it self.

I haven't been able to really find any article that discuss acceptable ways of doing it. And my concern with my current idea is that having a main root view controller which basically contains all views of the application and switches between them could quickly become messy?

Any input would be appriciated :)

Thanks in advance.

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

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

发布评论

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

评论(1

梦与时光遇 2025-01-08 09:17:27

我不久前一直在寻找类似的模式。根据我的发现,我得出的结论是,处理登录屏幕的最佳方法是将其注入主应用程序窗口。因此,您在 UIApplicationDelegate 类中执行此操作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([self loginNeeded])
    {
        [self presentLoginScreen];
    }else
    {
        [self presentTabBarController];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

,即 PresentLoginScreen 如下所示:

- (void)presentLoginScreen
{
    SMLoginViewController* loginVC=[[SMLoginViewController alloc] initWithNibName:@"SMLoginViewController" bundle:[NSBundle mainBundle]];
    [self.window setRootViewController:loginVC];
    [loginVC release];
}

类似地,在 [self presentTabBarController] 中,我创建包含实际应用程序的 UITabbarController,然后调用 [ self.window setRootViewController:tabbarController];

这很有用,因为您不会扩展不必要的视图层次结构。

I have been looking for similar pattern a while ago. From what I have found, I concluded that the best way to handle login screen is to inject it to main application window. So you are doing it in your UIApplicationDelegate class

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([self loginNeeded])
    {
        [self presentLoginScreen];
    }else
    {
        [self presentTabBarController];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

And i.e. presentLoginScreen looks like this:

- (void)presentLoginScreen
{
    SMLoginViewController* loginVC=[[SMLoginViewController alloc] initWithNibName:@"SMLoginViewController" bundle:[NSBundle mainBundle]];
    [self.window setRootViewController:loginVC];
    [loginVC release];
}

Analogically, in [self presentTabBarController] I create UITabbarController containing actual application and then call [self.window setRootViewController:tabbarController];

This is useful, as you don't expand you view hierarchy unnecessary.

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