将TabBarController更改为分段控件

时间:2012-05-08 07:09:53

标签: ios uinavigationcontroller uitabbarcontroller uisegmentedcontrol

在iOS 5食谱一书中,核心数据章节示例有一个3节的标签栏控制器,用于通过导航栏上的+按钮选择要添加的数据实体(以TableView格式)。想要查看。我想要一个3节分段控件用于相同的目的,但在顶部。我对此没有发言权。原始代码仅使用1个视图控制器,但创建3个不同的ivars(每个部分一个)。这三个实体是教师,仪器和工具。学生。

我最大的问题似乎是编写AppDelegate的didFinishLaunchingWithOptions方法。

这是原始代码(AppDelegate.m):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    NSLog(@"%@", [self managedObjectModel]);
    self.teacherTable = [[MainTableViewController alloc] init];
    NSLog(@"%@", [self managedObjectModel]);
    self.teacherTable.entityDescription = [NSEntityDescription entityForName:@"Teacher" inManagedObjectContext:self.managedObjectContext];
    self.teacherTable.managedObjectContext = self.managedObjectContext;
    self.teacherTable.title = @"Teachers";

    self.studentTable = [[MainTableViewController alloc] init];
    self.studentTable.entityDescription = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:self.managedObjectContext];
    self.studentTable.managedObjectContext = self.managedObjectContext;
    self.studentTable.title = @"Students";

    self.instrumentTable = [[MainTableViewController alloc] init];
    self.instrumentTable.entityDescription = [NSEntityDescription entityForName:@"Instrument" inManagedObjectContext:self.managedObjectContext];
    self.instrumentTable.managedObjectContext = self.managedObjectContext;
    self.instrumentTable.title = @"Instruments";

    self.teacherNavcon = [[UINavigationController alloc] initWithRootViewController:self.teacherTable];
    self.studentNavcon = [[UINavigationController alloc] initWithRootViewController:self.studentTable];
    self.instrumentNavcon = [[UINavigationController alloc] initWithRootViewController:self.instrumentTable];

    self.tabBarController = [[UITabBarController alloc] init];
    [self.tabBarController setViewControllers:[NSArray arrayWithObjects:self.teacherNavcon, self.studentNavcon, self.instrumentNavcon, nil]];

    [self.window addSubview:self.tabBarController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

感谢您的帮助!

0 个答案:

没有答案
相关问题