收到 NSInvalidArguementException 错误

2024-06-28

我想这可能与过度释放有关?它不断崩溃if (![managedObjectContext save:&error])就像每三次调用该方法一样(当我添加 3 个练习时)。

更新:我注意到当我往返于不同的例程实例时会发生这种情况。

2011-04-28 04:02:58.160 Curl[8035:707] Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  -[__NSCFDictionary controllerWillChangeContent:]: unrecognized selector sent to instance 0x1ba1b0 with userInfo (null)
    2011-04-28 04:02:58.353 Curl[8035:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary controllerWillChangeContent:]: unrecognized selector sent to instance 0x1ba1b0'

method

-(void)addExercise
{   
    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        [managedObjectContext retain];
    }

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

    NSError *error = nil;

    Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];

    exercise.name = selectedExercise;

    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);

    [theSelectedRoutine addRoutineToExercisesObject:exercise];

    if (![managedObjectContext save:&error]) 
    {
        // Handle the error.
    }
    NSLog(@"%@", error);
    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);
    [self.routineTableView reloadData];

}

这是完整的代码:

@implementation RoutineDayTableViewController

@synthesize fetchedResultsController;
@synthesize exerciseChooserView;
@synthesize routineTableView;
@synthesize managedObjectContext;
@synthesize selectedExercise;
@synthesize entityArray;
@synthesize theSelectedRoutine;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    NSLog(@"dealloc");
    [fetchedResultsController release];
    [selectedExercise release];
    [managedObjectContext release];
    [exerciseChooserView release];
    [routineTableView release];
    [entityArray release];
    [theSelectedRoutine release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, imagtaes, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

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

    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        [managedObjectContext retain];
    }
    [self loadData];
}

-(void)loadData
{
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    NSManagedObject *selectedObject = [entityArray objectAtIndex:indexPath.row];

    NSLog(@"After managedObjectContext: %@",  managedObjectContext);

    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    if (mutableFetchResults == nil) {
        // Handle the error.
    }
    self.entityArray = mutableFetchResults;

    [request setPredicate: [NSPredicate predicateWithFormat: @"routineExercises = %@", selectedObject]];    

    [mutableFetchResults release];
    [request release];
}

- (void)viewDidUnload
{
    NSLog(@"viewDidUnload");
    [super viewDidUnload];
    self.exerciseChooserView = nil;
    self.routineTableView = nil;
    self.fetchedResultsController = nil;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Exercise Editing

-(IBAction)exerciseChooser
{
    RoutineExerciseChooserViewController *routineExerciseChooserViewController = [[[RoutineExerciseChooserViewController alloc] init] autorelease];
    [self.navigationController pushViewController:routineExerciseChooserViewController animated:YES];
}

-(void)addExercise
{   
    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        [managedObjectContext retain];
    }

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

    NSError *error = nil;

    Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];

    exercise.name = selectedExercise;

    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);

    [theSelectedRoutine addRoutineToExercisesObject:exercise];

    if (![managedObjectContext save:&error]) 
    {
        // Handle the error.
    }
    NSLog(@"%@", error);
    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);
    //[self.routineTableView reloadData];
}

-(void)toggleEdit
{
    [self.routineTableView setEditing: !self.routineTableView.editing animated:YES];

    if (self.routineTableView.editing)
        [self.navigationItem.rightBarButtonItem setTitle:@"Cancel"];
    else
        [self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[self.fetchedResultsController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

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

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

    Exercise *tempExercise = (Exercise *)[fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = tempExercise.name;

    return cell;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
        [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
        NSLog(@"fetched results : \n%@\n",[self.fetchedResultsController fetchedObjects]);

        // Commit the change.
        NSError *error = nil;

        // Update the array and table view.
        if (![managedObjectContext save:&error]) 
        {
            // Handle the error.
        }
        //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[managedObject valueForKey:@"name"] description];
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    [routineTableView deselectRowAtIndexPath:indexPath animated:YES];

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
}

#pragma mark - Fetched results controller

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

    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    NSLog(@"fetchedResultsController theSelectedRoutine: %@",theSelectedRoutine);
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"ANY exerciseToRoutine == %@", theSelectedRoutine]];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&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();
    }
    return fetchedResultsController;

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];
}    

#pragma mark - Fetched results controller delegate

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    [self.routineTableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
    switch(type)
    {
        case NSFetchedResultsChangeInsert:
            [self.routineTableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.routineTableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    UITableView *tableView = self.routineTableView;

    switch(type)
    {

        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.routineTableView endUpdates];
}
@end

更新 - 这是新的更新代码:

@implementation RoutineDayTableViewController

@synthesize fetchedResultsController;
@synthesize exerciseChooserView;
@synthesize routineTableView;
@synthesize managedObjectContext;
@synthesize selectedExercise;
@synthesize theSelectedRoutine;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    NSLog(@"dealloc");
    [fetchedResultsController release];
    [selectedExercise release];
    [managedObjectContext release];
    [exerciseChooserView release];
    [routineTableView release];
    [theSelectedRoutine release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, imagtaes, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

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

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

- (void)viewDidUnload
{
    NSLog(@"viewDidUnload");
    [super viewDidUnload];
    self.exerciseChooserView = nil;
    self.routineTableView = nil;
    self.fetchedResultsController = nil;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Exercise Editing

-(IBAction)exerciseChooser
{
    RoutineExerciseChooserViewController *routineExerciseChooserViewController = [[[RoutineExerciseChooserViewController alloc] init] autorelease];
    [self.navigationController pushViewController:routineExerciseChooserViewController animated:YES];
}

-(void)addExercise
{   
    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        [managedObjectContext retain];
    }

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

    NSError *error = nil;

    Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];

    exercise.name = self.selectedExercise;

    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);

    [theSelectedRoutine addRoutineToExercisesObject:exercise];

    if (![fetchedResultsController.managedObjectContext save:&error]) 
    {
        // Handle the error.
    }
    NSLog(@"%@", error);
    NSLog(@"addExercise theSelectedRoutine:  %@", theSelectedRoutine);
    //[self.routineTableView reloadData];
    [exercise release];
    [error release];
}

-(void)toggleEdit
{
    [self.routineTableView setEditing: !self.routineTableView.editing animated:YES];

    if (self.routineTableView.editing)
        [self.navigationItem.rightBarButtonItem setTitle:@"Cancel"];
    else
        [self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[self.fetchedResultsController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

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

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

    Exercise *tempExercise = (Exercise *)[fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = tempExercise.name;

    return cell;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
        [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
        NSLog(@"fetched results : \n%@\n",[self.fetchedResultsController fetchedObjects]);

        // Commit the change.
        NSError *error = nil;

        // Update the array and table view.
        if (![fetchedResultsController.managedObjectContext save:&error]) 
        {
            // Handle the error.
        }
        //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[managedObject valueForKey:@"name"] description];
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    [routineTableView deselectRowAtIndexPath:indexPath animated:YES];

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
}

#pragma mark - Fetched results controller

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

    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    NSLog(@"fetchedResultsController theSelectedRoutine: %@",theSelectedRoutine);
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"ANY exerciseToRoutine == %@", theSelectedRoutine]];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&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();
    }

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];
    return fetchedResultsController;
}    

#pragma mark - Fetched results controller delegate

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    [self.routineTableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
    switch(type)
    {
        case NSFetchedResultsChangeInsert:
            [self.routineTableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.routineTableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    UITableView *tableView = self.routineTableView;

    switch(type)
    {

        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.routineTableView endUpdates];
}
@end

您正在混合两种完全独立的访问核心数据信息的方式。对于每个表视图,您应该只有一个上下文引用和一次提取。您至少有两个同时运行的提取和两个上下文引用。您需要选择其中之一。如果您使用的是获取结果控制器,那么您不需要其中的代码viewDidLoad and loadData.

您还需要使用self引用属性时的参考,例如你需要使用self.selectedExercise而不是仅仅selectedExercise。只有self参考表可以让您自动保留和释放。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

收到 NSInvalidArguementException 错误 的相关文章

  • iOS9 按需访问和下载资源

    我正在尝试实现新的 iOS9 功能应用程序细化 我了解如何在 Xcode 7 中标记图像并启用按需资源 但我不明白如何在我的应用程序中实现 NSBundleResourceRequest 有人可以帮助我 我将不胜感激 大部分信息都可以在 A
  • 有没有办法使用 setValue:forKey 来获取 C 类型变量?

    我在对象上设置了一些属性 大部分是GLfloat我想知道是否有办法使用 self setValue id value forKey id key 那需要一个c风格的变量吗 不一定是这样setValue forKey是否有替代方案 如果有可用
  • 以编程方式创建图像的缩略图

    在我的应用程序中 我从服务器获取图像 并且能够在图像视图中显示图像 但现在我想将从服务器获取的图像存储在表视图中 并在单击表视图单元格时显示它们 我想要的是如何制作图像的缩略图 以便将其显示在表视图单元格中 如果我直接在表视图单元格中显示图
  • NSPredicate 核心数据

    两者之间的确切区别是什么LIKE c and c 在核心数据中NSPredicate 我想搜索一个与接收者完全匹配的字符串 例子 NSArray arrayNames context fetchObjectsForEntityName NS
  • iPhone 向右翻转按钮(如 iTunes)

    我正在尝试在两种视图之间切换 这很简单 代码如下 但我还想同时翻转用于执行翻转的按钮 当您播放曲目时 您可以在 iPod 应用程序中看到此行为 点击翻转按钮可在封面艺术和曲目列表之间翻转 但同时会翻转按钮 这是导航控制器上的一个页面 我要翻
  • AVPlayer 持续时间对于 Twilio 来说是 NAN

    The duration的财产AVPlayer currentItem正在返回NAN总是与Twilio音频网址 不过 音频播放得很好 我能够得到duration除 Twilio 之外的所有其他音频 url 的属性 测试此问题的示例网址 ht
  • itunesconnect 在防火墙后面使用应用程序加载器

    我试图将我的应用程序的应用程序商店构建 zip 文件上传到应用程序商店 当在我的办公室防火墙后面使用时 TCP IP 连接失败 我需要知道应该打开哪个端口来使用应用程序加载器上传 iPhone 应用程序 这样端口就可以打开了 或者任何其他配
  • iPhone 中 didReceiveMemoryWarning 方法中发生 level=2 警告时如何获取警报[重复]

    这个问题在这里已经有答案了 可能的重复 调用 didReceiveMemoryWarning 时向用户生成警报 https stackoverflow com questions 1992784 generating alert to us
  • CAShapeLayer 具有边框、填充颜色和舍入

    如何使用 CAShapeLayer 绘制一条同时具有边框颜色 边框宽度和填充颜色的线条 这是我尝试过的 但它只是蓝色的 self lineShape strokeColor UIColor blueColor CGColor self li
  • 模块“Alamofire”没有名为“SessionManager”的成员

    为什么我会收到此错误 我没有收到 我已经将 Alamofire 更改为 AF 就像使用 Alamofire 5 一样 请指导哪里出了问题以及需要更改什么 下面是我收到错误的代码 private func callAlamoFireForma
  • Cocoapod 的 Xcode 错误:“无法保存文档。文件不存在”

    我已经添加了SPGooglePlacesAutocompletecocoapod 到我的项目 我遇到了一个非常奇怪的问题 当我尝试运行我的项目时 Xcode 提示 Pod 的标头之一存在错误 SPGooglePlacesAutocomple
  • 如何从 CVPixelBufferRef 转换为 openCV cv::Mat

    我想对一个执行一些操作CVPixelBufferRef并出来一个cv Mat 裁剪到感兴趣的区域 缩放到固定尺寸 均衡直方图 转换为灰度 每像素 8 位 CV 8UC1 我不确定最有效的顺序是什么 但是 我确实知道所有操作都可以在 open
  • 从 iPhone 应用程序上传图像

    我正在尝试从 iPhone 应用程序将图像上传到服务器 上传图片的PHP代码如下 if isset POST insertImage INSERT IMAGE method safeData POST insertImage if meth
  • 无需在线即可从 XMPP 获取离线消息

    我们的移动聊天应用程序使用 ejabberd 服务器 我们正在为我们的 IOS 应用程序使用 IOS XMPP Framework https github com robbiehanson XMPPFramework https gith
  • UIModalTransitionStyleFlipHorizo​​ntal 横向垂直翻转

    在横向模式下 从一个视图 导航控制器堆栈的一部分 转换到另一个视图作为模态视图 并将 UIModalTransitionStyleFlipHorizo ntal 设置为 modalTransitionStyle 视图在横向模式下垂直翻转 动
  • 文件从 iOS 应用程序传输到 Mac 应用程序?

    是否可以在 Mac 应用程序和 iOS 应用程序之间传输文件 我想通过 Wifi 将 iOS 应用程序中的文档目录中的文件传输到 Mac 应用程序 我该怎么做 嗯 从 iOS 5 开始 就有了 iCloud 由于这仍处于保密协议之下 我只需
  • Reactive Cocoa - 以编程方式设置文本时,不会调用 UITextView 的 rac_textSignal

    我正在实现一个聊天 UI 并使用 Reactive Cocoa 在用户键入时调整聊天气泡的大小 目前 我正在根据 textview 更新 UI 的布局rac textSignal 一切都工作得很好 除了一点 当用户sends消息中 我以编程
  • XCode 5 在 AppStore 验证中崩溃

    我是 iOS 开发新手 很可能错过了一些相关的东西 我有一个在 Xcode 中开发的应用程序 并使用开发设备进行了测试 以便我知道它运行正常 我已在 iTunes Connect 中创建了记录 并完成了启用 等待上传 状态的步骤 在构建设置
  • CoreGraphics 和 CoreAnimation 有什么不同?

    我正在使用 coregraphics 开发 iphone 游戏 但速度很慢 我无法玩我的游戏 所以 我用谷歌搜索了很多 在谷歌搜索过程中 我发现了以下内容 CoreGraphics CoreAnimation OpenGL ES CALay
  • 快速判断文件是否为有效视频

    确定文件是否是可播放视频的最快方法是什么 我不关心它是否腐败 只关心它是否是哑剧类型should可以在 iPad 上播放 我玩过将文件推送到NSURL正如另一个问题所建议的 但每个文件可能需要 gt 1 秒 这太慢了 我目前正在查看文件扩展

随机推荐

  • zurb 基金会是否可以拥有完整的行宽度

    我正在使用 Foundation 3 构建响应式网站 但我想让页脚和导航背景宽度占据整个宽度 我将我的行命名为 class row navigation class row footer 我尝试寻找如何解决这个问题 但我没有选择 我假设这是
  • 如何使用 pip 安装 Openpyxl

    我有 Windows 10 64 位 我想利用Openpyxl包开始学习如何与 Excel 和其他电子表格交互 我安装了Python windowsx86 64web basedinstaller 我有 64 位操作系统 尝试安装此版本时我
  • Helm 安装未知标志 --name

    当我尝试使用 helm 安装图表时 helm install stable nginx ingress name my nginx 我收到错误 错误 未知标志 name 但我在很多文档中都看到了上面的命令格式 版本 version Buil
  • IntelliJ 的 javafx 集成场景生成器在 Oracle JDK 12 中无法工作

    我正在运行 Arch Linux 安装了最新的 IntelliJ 包以及 Oracle 的 JDK12 项目使用的 和 Gluon 的场景生成器 场景生成器的路径已正确设置 场景生成器独立工作 也是从 IntelliJ 启动时 我右键单击我
  • 房间数据库:插入的ID始终为0

    我正在尝试创建列表项的房间数据库 我在这里遵循这个例子 https medium com mindorks room kotlin android architecture components 71cad5a1bb35 https med
  • Spring 排序的 beans 列表

    我有几个实现相同接口的 bean 每个 bean 都注释有 Component Order SORT ORDER public class MyClass implements BeanInterface 有一次 我自动装配了一个组件列表
  • EventMachine 的优势是什么

    这是我的测试用例 我发现EM并不比一般的TCP服务器快 EM 服务器 require rubygems require benchmark require eventmachine class Handler lt EventMachine
  • 断点在 xcode pod 文件中不起作用

    我有一个 xcode 项目 其中包含一些可可豆荚文件 当我在 cocoa pod 文件中放置断点时 调试器不会在这些断点处停止 为什么 有人对此有什么想法吗 我关注了 UdaySingh 的评论 它起作用了 我不确定他为什么没有发布答案 但
  • 基于百分比的路由算法

    四处浏览基于百分比的路由 偶然发现这个线程 https stackoverflow com a 52044571 3154233 根据建议的算法如下 对于给定模型如下 public class Host private String nam
  • 动态加载内容脚本(chrome扩展)

    我有一个 chrome 扩展 其中有 2 个由清单注入的内容脚本和一个后台脚本 manifest version 2 name Test permissions tabs
  • 假装下载文件

    我试图找到一种简单的方法来使用 Feign 下载 csv 文件 保留文件名 最简单 最干净的方法是什么 feign form github 页面上的多部分解决方案非常冗长 并且不适合我 任何帮助表示赞赏 假冒客户 import feign
  • 以编程方式在 Swift 中实现尾随和前导约束 (NSLayoutConstraints)

    我正在从 xib 添加一个视图到我的 ViewController 中 然后我将其限制真正适合它 override func viewDidAppear animated Bool super viewDidAppear animated
  • CUDA:注入我自己的PTX函数?

    我希望能够使用 PTX 1 3 中尚未在 C 接口上实现的功能 有没有办法在 PTX 中编写我自己的函数并注入到现有的二进制文件中 我正在寻找的功能是获取以下值 smid 答案 noinline device uint get smid v
  • 如何确保我的 HttpClient 4.1 不会泄漏套接字?

    我的服务器使用来自内部 Web 服务的数据根据 每个请求构建其响应 我正在使用 Apache HttpClient 4 1 发出请求 每个初始请求将导致对 Web 服务发出大约 30 个请求 其中 4 8 个套接字最终会陷入 CLOSE W
  • java中的自增和自减运算符

    我对增量和减量运算符有疑问 我无法理解为什么 java 给出这些输出 x 5 y 10 System out println z y x output is 50 x 2 y 3 z 4 System out println Result
  • 如何测量 Linux 中给定进程的活动导致的净使用磁盘空间变化?

    我想监视正在运行的进程的磁盘空间需求 理想情况下 我希望能够指向一个进程并找出由该进程引起的已用磁盘空间的净变化 在 Linux 中是否有一种简单的方法可以做到这一点 我很确定在 Solaris 中使用 DTrace 执行此操作是可行的 尽
  • Rebol 中的级联

    在标志语言中 cascade http www cs berkeley edu bh v1ch5 hof html是一个将函数与其自身组合多次的过程 它几乎就像fold用函数式语言 例子 add 4 add 4 add 4 5 gt cas
  • 一次性将所有 SQL Server 表导出为 txt 或 csv

    我有数百个 SQL Server 表需要导出到 txt 或 csv 文本限定符和 划定的 导入 导出向导一次仅允许一张表 有没有更好的方法 工具 脚本来同时完成这一切 Thanks 您可以使用以下命令对 BCP 执行某些操作 SELECT
  • 我的 PHP 脚本如何判断服务器是否繁忙?

    我想运行一个 cron 作业来进行清理 需要大量的 CPU 和 Mysql 资源 我希望它仅在服务器不相对繁忙时运行 从 PHP 中确定这一点的最简单方法是什么 例如 是否有一个查询返回最后一分钟完成了多少个查询 if function e
  • 收到 NSInvalidArguementException 错误

    我想这可能与过度释放有关 它不断崩溃if managedObjectContext save error 就像每三次调用该方法一样 当我添加 3 个练习时 更新 我注意到当我往返于不同的例程实例时会发生这种情况 2011 04 28 04