1

我在C和C++方面有经验,但在Objective C或Xcode4中几乎没有经验。适用于iOS的应用程序组织

我正在创建一个带有标签栏,导航栏和表格视图的应用程序。基于我的知识,我假设我从顶层开始钻入根目录?

第一个 创建myTableViewController类,它将动态创建tableview内容并将其创建的视图推送到导航控制器上。 然后... 创建包含myTableViewController的myNavController类。用一个为myTableViewController创建一个新项目的方法。 然后... 创建一个标签栏控制器,它具有上面作为其中一个标签的数组以及其他标签,将标签栏控制器设置为根控制器并将其显示到窗口中。

这是正确的思维方向吗?还是我可怕的偏离路线?

+0

“思考的正确方向”是Interface Builder :) – jtbandes

+0

EricS,从以下示例开始:http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html# // apple_ref/DOC/UID/DTS40008913-简介-DontLinkElementID_2 – magma

回答

0

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

这里是我的应用程序代理如何处理这样的:

- (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; 
} 

享受!