【问题标题】:TabBar application, CoreData related application crashTabBar 应用,CoreData 相关应用崩溃
【发布时间】:2011-06-03 17:36:05
【问题描述】:

在我的项目中,我使用 tabBarController 作为 rootView 控制器,然后在我的一个选项卡上,添加我现有的 ToDoList 应用程序。我遇到的问题是:如果我在 AppDelegate 中使用此代码:ToDoList 加载为 RootView。但我希望它仅在选择适当的选项卡后显示。

- (void)applicationDidFinishLaunching:(UIApplication *)application {  
    //todoRootController.managedObjectContext = self.managedObjectContext;
    ToDoRootViewController *todoRootViewController = [[ToDoRootViewController alloc]initWithNibName:@"ToDoRootViewController" bundle:nil];
    NSManagedObjectContext *context = [self managedObjectContext];

    if (!context) {
        // Handle the error.
    }

    // Pass the managed object context to the view controller.
    todoRootViewController.managedObjectContext = context;
    UINavigationController *aNavigationController = [[UINavigationController alloc]                                                  
                                                     initWithRootViewController:todoRootViewController];
    self.navigationController = aNavigationController;

    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
    [todoRootViewController release];

    [aNavigationController release];
}

我将 applicationDidFinishLaunching:(UIApplication *)application 方法替换为 CoreDataReceipeis 示例代码

- (void)applicationDidFinishLaunching:(UIApplication *)application {  
    todoRootController.managedObjectContext = self.managedObjectContext;

//////////////// same stuff
}

但是它给出了'NSInternalInconsistencyException',原因:'+entityForName:找不到实体名称'Task''的NSManagedObjectModel

【问题讨论】:

  • 默认情况下,第一个选项卡在调用选项卡控制器时显示。您是否希望第一个选项卡的视图控制器仅在被触摸时显示?

标签: iphone cocoa-touch ios core-data ios-3.x


【解决方案1】:

利用 Interface Builder 设置在键入选项卡时将显示的选项卡视图控制器。

如果您必须以编程方式进行,那么您应该查看 TabBarControllers 的文档。

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

  tabBarController = [[UITabBarController alloc] init]; 

  MyViewController* vc1 = [[MyViewController alloc] init]; 

  MyOtherViewController* vc2 = [[MyOtherViewController alloc] init]; 

  NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil]; 

  tabBarController.viewControllers = controllers; 

  // Add the tab bar controller's current view as a subview of the window 
  [window addSubview:tabBarController.view];

} 

【讨论】:

  • 我已在界面生成器中将我的 ToDoListViewController 设置为适当的选项卡。但正如我所提到的,如果我使用第一个代码段,ToDoListViewController 将作为 rootview 加载。如果我使用第二个代码段,它会给出上述异常。我真的受够了这个:( :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多