Ios 无法获取核心数据以删除表视图行

Ios 无法获取核心数据以删除表视图行,ios,core-data,Ios,Core Data,我得到以下错误: Unresolved error (null), (null) 任何想法,这可能是相关的-我正试图让用户刷卡选项删除核心数据的项目。。。添加和显示数据有效-但是删除显示错误 @implementation List @synthesize eventsArray; @synthesize managedObjectContext, fetchedResultsController, List; ... - (void)viewDidLoad { [super v

我得到以下错误:

Unresolved error (null), (null)
任何想法,这可能是相关的-我正试图让用户刷卡选项删除核心数据的项目。。。添加和显示数据有效-但是删除显示错误

@implementation List

@synthesize eventsArray;
@synthesize managedObjectContext, fetchedResultsController, List;

...

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(ApplicationAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
    }


    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editAction)];
    self.navigationItem.leftBarButtonItem = editButton;

    [editButton release];

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target: self action:@selector(addAction)];
    self.navigationItem.rightBarButtonItem = addButton;

    [addButton release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.fetchedResultsController.delegate = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    List = [[NSMutableArray alloc] init];

    NSError *error;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Items" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
    NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

    for (NSManagedObject *info in fetchedObjects)
    {
        [List insertObject:[info valueForKey:@"Name"] atIndex:0];
    }
    [fetchRequest release];
    [self.tableView reloadData];
}

...

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [List count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Get and display the values for the keys; the key is the attribute name from the entity 
    cell.textLabel.text = [List objectAtIndex:indexPath.row];

    // Add a standard disclosure for drill-down navigation
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {

        NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
        [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

        // Save the context.
        NSError *error = nil;
        if (![context save:&error])
        {
            /*
             Replace this implementation with code to handle the error appropriately.

             abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
             */
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }    }
}


- (void)dealloc
{
    [fetchedResultsController release];
    [List release];
    [super dealloc];
}

@end

首先,您的视图控制器实现的名称为“列表”,但似乎也有一个ivar命名列表。检查视图控制器类的名称,因为它应该是@implementation声明性名称之后的名称


此外,如果NSArray的名称是List,那么通常的编码约定是保持ivar以小写开头。将类名保留为大写,将IVAR保留为小写应有助于避免将来的混淆。

应用程序中是否使用多线程?比如在不同的线程中使用相同的上下文还是什么?@HeikoG-我不这么认为……对不起-List实际上在应用程序中不是真正的List-它实际上是以我正在开发的应用程序名命名的-但是由于保密性,我不得不更改名称。