ios - iOS 的应用程序组织

标签 ios uinavigationcontroller uitabbarcontroller uitableview

我有 C 和 C++ 方面的经验,但在 Objective C 或 Xcode4 方面几乎为零。

我想创建一个带有选项卡栏、导航栏和表格 View 的应用程序。根据我所掌握的知识,我假设我从顶部开始并向下钻取到根部?

首先 创建 myTableViewController 类,它将动态创建 tableview 内容并将其创建的 View 推送到导航 Controller 上。 然后... 创建包含 myTableViewController 的 myNavController 类。使用为 myTableViewController 创建新项目的方法。 然后... 创建 Tab Bar Controller,将上面的内容作为数组中的选项卡之一以及其他一些选项卡,将选项卡栏 Controller 设置为根 Controller 并将其显示到窗口。

这是正确的思考方向吗?还是我严重偏离了路线?

最佳答案

我有一个具有这些相同要求的应用程序。它有一个 UITabBar,在不同的选项卡中,每个 UITableViewController 的顶部都有一个 UINavigationController 导航栏。

这是我的 App Delegate 处理这个问题的方式:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Create the UITabBarController
    UITabBarController *tabBarController = [[UITabBarController alloc] init];

    //Create the view controllers for our tabs
    UITableViewController *vc1 =     [[UITableViewController  alloc] init];
    UITableViewController *vc2 =     [[UITableViewController  alloc] init];
    UITableViewController *vc3 =     [[UITableViewController  alloc] init];
    UITableViewController *vc4 =     [[UITableViewController  alloc] init];
    UITableViewController *vc5 =     [[UITableViewController  alloc] init];

    //Create the Navigation Controllers for these views
    UINavigationController *nc1 = [[[UINavigationController alloc]
                                    initWithRootViewController:vc1] autorelease];
    UINavigationController *nc2 = [[[UINavigationController alloc]
                                    initWithRootViewController:vc2] autorelease];
    UINavigationController *nc3 = [[[UINavigationController alloc]
                                    initWithRootViewController:vc3] autorelease];
    UINavigationController *nc4 = [[[UINavigationController alloc]
                                    initWithRootViewController:vc4] autorelease];
    UINavigationController *nc5 = [[[UINavigationController alloc]
                                    initWithRootViewController:vc5] autorelease];


    //Make an array containing the view controllers
    NSArray *viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nc4, nc5, nil];

    //The NSArray has retained these controllers, we can now release them.
    [vc1    release];
    [vc2    release];
    [vc3    release];
    [vc4    release];
    [vc5    release];

    [nc1    release];
    [nc2    release];
    [nc3    release];
    [nc4    release];
    [nc5    release];

    //Assign the view controllers to the tab bar.
    [tabBarController setViewControllers:viewControllers];

    //Set tabBarController as rootViewController of window
    [self.window setRootViewController:tabBarController];

    //The window retains tabBarController, we can release our reference
    [tabBarController release];


    [self.window makeKeyAndVisible];
    return YES;
}

尽情享受吧!

关于ios - iOS 的应用程序组织,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7217918/

相关文章:

iphone - 如何在具有导航的 Tabbar 应用程序中调用 viewWillDisappear 方法

objective-c - 对于 Objective-C,实现值对数组的最有效方法是什么?

ios - 如何在导航栏上显示后退按钮?

ios - 如何调试以 NSException 类型的未捕获异常终止

ios - 取消按钮未显示在 iPad 模式的 UINavigationController 中

ios - 容器 View 中的 UINavigationController : push segue on table view cell does nothing

ios - 如何在 didSelectRow 之后关闭 UISearchController?

ios - 将图像添加到选项卡栏项目仅显示为 block

ios - AES 加密算法无法解密少数文档格式

javascript - Youtube 识别其已安装的应用程序 : how?