【问题标题】:App Organization for iOSiOS 应用组织
【发布时间】:2011-11-05 06:49:50
【问题描述】:

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

我希望创建一个带有标签栏、导航栏和表格视图的应用。根据我所拥有的知识,我假设我从顶部开始并深入到根?

首先 创建 myTableViewController 类,该类将动态创建 tableview 内容并将其创建的视图推送到导航控制器。 然后... 创建包含 myTableViewController 的 myNavController 类。使用为 myTableViewController 创建新项目的方法。 然后... 创建标签栏控制器,将上述作为其标签之一的数组与其他一些标签一起,将标签栏控制器设置为根控制器并将其显示到窗口。

这是正确的思考方向吗?还是我非常偏离路线?

【问题讨论】:

标签: ios uinavigationcontroller uitabbarcontroller uitableview


【解决方案1】:

我有一个具有这些相同要求的应用。它有一个 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;
}

享受吧!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多