核心数据和Master-Detail模板,获得运行时异常。

时间:2013-08-03 10:29:04

标签: ios core-data storyboard master-detail

我正在尝试修改xcode生成的Master Detail项目模板。 但是得到以下问题:

  2013-08-03 20:08:59.749 StudentsAtWork[20236:a0b] Unknown class cblMasterViewController in Interface Builder file.
  2013-08-03 20:08:59.900 StudentsAtWork[20236:a0b] -[UITableViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x8ec8120
  2013-08-03 20:08:59.904 StudentsAtWork[20236:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x8ec8120'
  *** First throw call stack:
  (0x1a009b8 0x17818b6 0x1a9cc13 0x19f0cfb 0x19f08de 0x61ee 0x57bea9 0x57c6e9 0x57db5e 0x593a6c 0x593fd9 0x57f7d5 0x38ce906 0x38ce411 0x197c3e5 0x197c11b 0x19a6b30 0x19a610d 0x19a5f3b 0x57d2b1 0x57f4eb 0x6d7d 0x2060725)
  libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

我基本上做了什么,删除了生成的主视图和详细视图控制器类,并创建了我自己的MasterViewController类,如下所示:

头文件:

   #import <UIKit/UIKit.h>

   @interface cblMasterViewController : UITableViewController

   @property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;

   @end

实施档案:

   #import "cblMasterViewController.h"

   @interface cblMasterViewController ()

   @end

   @implementation cblMasterViewController

   @synthesize managedObjectContext;

  ....
  ....

  @end

我的app委托代码如下:

  #import "cblAppDelegate.h"
  #import "cblMasterViewController.h"

  @implementation cblAppDelegate

  @synthesize managedObjectContext = _managedObjectContext;
  @synthesize managedObjectModel = _managedObjectModel;
  @synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
 {
  // Override point for customization after application launch.
 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
    splitViewController.delegate = (id)navigationController.topViewController;

    UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
    cblMasterViewController *controller = (cblMasterViewController *)masterNavigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;
} else {
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    cblMasterViewController *controller = (cblMasterViewController *)navigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;
   //}
   return YES;
   }

我也从故事板中删除了详细视图。

我是使用故事板的新手。所以我不确定这里出了什么问题。 谁能给我一些线索?

感谢。

0 个答案:

没有答案