1

我正在尝试修改 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

我的应用委托代码如下:

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

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

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

谢谢。

4

0 回答 0