1

在 iOS 5 Recipes 一书中,Core Data 章节示例有一个 3 部分的选项卡栏控制器,用于通过导航栏上的 + 按钮选择要添加的数据实体(TableView 格式)并查看。我想要一个用于相同目的但位于顶部的 3 段分段控件。在这方面我没有发言权。原始代码仅使用 1 个视图控制器,但创建了 3 个不同的 ivars(每个部分一个)。3 个实体是教师、仪器和学生。

我最大的问题似乎是编写 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;
}

谢谢您的帮助!

4

0 回答 0