核心数据:严重应用程序错误 [英] Core data: Serious application error
问题描述
我完成了我的核心数据应用程序,我开始了最后的测试。
Everyfing工作正常,除非一件事,发生随机
b $ b
2011-07-03 20:27:53.144 MYAPP [1882:707] - [__ NSCFType controllerWillChangeContent:]:无法识别的选择器发送到实例0x4a4c490
2011-07-03 20:27:53.149 MYAPP [1882:707]严重的应用程序错误。在核心数据更改处理期间捕获异常。这通常是NSManagedObjectContextObjectsDidChangeNotification的观察器中的错误。 - [__ NSCFType controllerWillChangeContent:]:无法识别的选择器发送到实例0x4a4c490 with userInfo(null)
2011-07-03 20:27:53.165 MYAPP [1882:707] CoreAnimation:忽略异常: - [__ NSCFType controllerWillChangeContent:]:无法识别的选择器发送到实例0x4a4c490
在此崩溃:
$ b b
NSManagedObjectContext * context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; // IT'S OK
NSManagedObject * newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@KontrahentinManagedObjectContext: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。打开应用程序
2.打开我的'根'列表(使用NSFetchedResultsController,entity:Faktura)
3.点击添加按钮
4.在我的'添加'另一个对象(实体:Kontrahent)
5.我尝试将其添加到数据库
6.崩溃/它不。
SCHEME:
+ --- [moc save:] ---> Faktury(我的根类)
| ↓
+ ----- delegate-- FakturaCreator< --- [moc save:] - +& - --- ---这里是
↓|
KontrahentCreator --- delegate --- +
我知道它与 NSFetchedResultsController
和 [moc save:]
。但我找不到我的问题,因为它崩溃,当它想要。有时它工作,有时它崩溃。如果您知道这个问题,请帮助我:)
如果您需要更多代码...
NSFetchedResultsController stuff (Faktury.m)
#pragma mark - 获取结果控制器
- (NSFetchedResultsController *)fetchedResultsController {
if(__fetchedResultsController!= nil) return __fetchedResultsController;
//设置表
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription * entity = [NSEntityDescription entityForName:@FakturainManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
//设置排序描述符
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@NumerFVascending:YES];
NSArray * sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor,nil];
[fetchRequest setSortDescriptors:sortDescriptors];
//创建获取结果控制器
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łądKrytycznymessage:@Wystąpiłnieznanybłąd przy zmienianiuzawartościw bazie danych。Dla dobra twoich danych prosimyniezwłoczniewyjśćz aplikacji ispróbowaćponownie。 delegate:self cancelButtonTitle:@OKotherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@未解决的错误%@,%@,错误,[错误userInfo]);
abort();
}
return __fetchedResultsController;
}
#pragma mark - 获取结果控制器委托
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[tableView beginUpdates]; (NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type(NSFetchedResultsChangeType)(NSFetchedResultsChangeType) {
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: )type newIndexPath:(NSIndexPath *)newIndexPath {
if([[[sections] objectAtIndex:0] numberOfObjects] == 0){
emptySectionView.hidden = NO;
UIBarButtonItem * editBtn = [[UIBarButtonItem alloc] initWithTitle:@Edytujstyle: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:
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
和modal被驳回并释放。
我已经解决了我的问题:
self.fetchedResultsController.delegate = nil;方法中的<
>
I'm finishing my Core Data app ans I started my final testing.
Everyfing works fine, except one thing, that happens randomly and I can't reproduce it.
Here is the log (with 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
It crashes here:
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();
}
My action hierarchy:
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---+
I know that it's connected with NSFetchedResultsController
and [moc save:]
. But I can't locate my problem, because it crashes when it wants. Sometimes it works, sometimes it crashes. If you know something abou this problem, please help me :)
IF YOU NEED MORE CODE...
NSFetchedResultsController stuff (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];
}
When I tap the add button (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];
}
OK, I located my problem. I have a 'KontrahentPicker' and it has NSFetchedResultsController
too. But this UIViewController
was presented as modalViewController
. I pucked my Kontrahent
and modal was dismissed and released. But NSFRC
's delegate was still active.
I solved my problem by putting
self.fetchedResultsController.delegate = nil;
in -dealloc
method.
这篇关于核心数据:严重应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!