gpt4 book ai didi

iphone - 核心数据: Serious application error

转载 作者:行者123 更新时间:2023-12-03 19:10:45 28 4
gpt4 key购买 nike

我正在完成我的 Core Data 应用程序,并开始最终测试。

Everyfing 工作正常,除了一件事,它是随机发生的,而且我无法重现它。

这是日志(使用 NSZombieEnabled):

2011-07-03 20:27:53.144 MYAPP[1882:707] -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490
2011-07-03 20:27:53.149 MYAPP[1882:707] Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490 with userInfo (null)
2011-07-03 20:27:53.165 MYAPP[1882:707] CoreAnimation: ignoring exception: -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490

它在这里崩溃了:

NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; // IT'S OK
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Kontrahent" inManagedObjectContext:context]; // IT'S OK
for(NSString *key in kontrahent) [newManagedObject setValue:[kontrahent valueForKey:key] forKey:key]; // IT'S OK
NSError *error = nil;
if (![context save:&error]) { // IT'S NOT OK
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

我的操作层次结构:

1. Open application
2. Open my 'root' list (with NSFetchedResultsController, entity: "Faktura")
3. Tap 'Add' button
4. In my 'Add' view controller I create another object (entity: "Kontrahent")
5. I try to add it to database
6. It crashes / It doesn't.

SCHEME:

+---[moc save:]---> Faktury (my root class)
| ↓
+-----delegate-- FakturaCreator <---[moc save:]--+ <--- HERE IT CRASHES
↓ |
KontrahentCreator ---delegate---+

我知道它与 NSFetchedResultsController[moc save:] 连接。但我找不到我的问题,因为它会在需要时崩溃。有时它有效,有时它崩溃。如果您知道这个问题,请帮助我:)

<小时/>

如果您需要更多代码...

NSFetchedResultsController 内容(Faktury.m)

#pragma mark - Fetched results controller

- (NSFetchedResultsController *)fetchedResultsController {

if (__fetchedResultsController != nil) return __fetchedResultsController;

// Setup the table

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Faktura" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Setup the sort descriptors

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

// Create the fetched results controller

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

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

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Błąd Krytyczny" message:@"Wystąpił nieznany błąd przy zmienianiu zawartości w bazie danych. Dla dobra twoich danych prosimy niezwłocznie wyjść z aplikacji i spróbować ponownie." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return __fetchedResultsController;
}

#pragma mark - Fetched results controller delegate

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[tableView beginUpdates];
}

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

case NSFetchedResultsChangeDelete:
[tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

if([[[controller sections] objectAtIndex:0] numberOfObjects] == 0) {
emptySectionView.hidden = NO;
UIBarButtonItem *editBtn = [[UIBarButtonItem alloc] initWithTitle:@"Edytuj" style:UIBarButtonItemStyleBordered target:self action:@selector(toogleEditing)];
editBtn.enabled = NO;
[self.navigationItem setLeftBarButtonItem:editBtn animated:NO];
[editBtn release];
} else {
emptySectionView.hidden = YES;
self.navigationItem.leftBarButtonItem.enabled = YES;
}

UITableView *table = tableView;

switch(type) {

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

case NSFetchedResultsChangeDelete:
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
break;

case NSFetchedResultsChangeUpdate:
[self configureCell:(KSTableViewCell *)[table cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;

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

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[tableView endUpdates];
}

当我点击添加按钮时(Faktury.m)

- (void)add:(id)sender {
FakturaCreator *form = [[FakturaCreator alloc] init];
form.hidesBottomBarWhenPushed = YES;
form.delegate = self;
form.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:form animated:YES];
[form release];
}

最佳答案

好的,我找到了我的问题。我有一个“KontrahentPicker”,它也有 NSFetchedResultsController。但是这个UIViewController被呈现为modalViewController。我按下了 Kontrahent,模态被驳回并释放。但 NSFRC 的代表仍然活跃。

我通过放置解决了我的问题

self.fetchedResultsController.delegate = nil;

-dealloc方法中。

关于iphone - 核心数据: Serious application error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565422/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com