1

我一直在努力让它发挥作用。我似乎无法让幻灯片菜单和表格视图(带有数据)同时工作。我只能得到其中之一。

我相信这个问题存在于我的 AppDelegate 中。这是受影响的部分。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIStoryboard *countryStoryboard = [UIStoryboard storyboardWithName:@"Country" bundle:nil];
UINavigationController *navigationController = [countryStoryboard instantiateInitialViewController];
MetallurgyMasterViewController *countryViewController = (MetallurgyMasterViewController *)navigationController.topViewController;

__managedObjectContext = self.managedObjectContext;
countryViewController.managedObjectContext = self.managedObjectContext;
[Country importDataToMoc:self.managedObjectContext];

self.window.rootViewController = navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

这是我的 TableViewController 中的相关部分。

- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil)
{
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSLog(@"The value of managedObjectContext is %@", self.managedObjectContext);
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Country" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                                      managedObjectContext:self.managedObjectContext 
                                                                        sectionNameKeyPath:@"sectionTitle"
                                                                                 cacheName:@"Country"];
frc.delegate = self;
self.fetchedResultsController = frc;

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error])
{
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

return _fetchedResultsController;
}    

在上面的设置中,我的桌子工作正常,但我似乎无法调出幻灯片菜单。

如果我在我的 AppDelegate 中替换以下行。

UINavigationController *navigationController = [countryStoryboard instantiateInitialViewController];

为了

UINavigationController *navigationController = [countryStoryboard instantiateViewControllerWithIdentifier:@"startView"];

并在我的 TableViewController 中注释掉 NSFetchedResultsController 方法,然后幻灯片菜单可以正常工作,但没有填充表格视图(我明白为什么没有数据)。如果我不将其注释掉,则 managedObject 为 NIL 并引发错误。

这可能很简单,但我想我已经看这个太久了。

4

0 回答 0