开发者

Changing Core Data Items crashes App

开发者 https://www.devze.com 2023-01-20 07:09 出处:网络
I am running into another problem with my Iphone App which I just can\'t solve myself. I implemented a kind of organizer functionality in my latest app.

I am running into another problem with my Iphone App which I just can't solve myself. I implemented a kind of organizer functionality in my latest app. There one can create appointments which are displayed in a tableview and persisted in a CoreDataStore. I use 4 classes:

  • an overview where appointments are displayed
  • a view with textfields to put in Values for place and name of appointment (create/edit view)
  • a view with DatePicker to define start- and enddate
  • a controller which handles creation and deletion of items using this methods:

The code:

-(void)createAppointmentObjectWithDate:(NSDate *)
                  appointmentDate name:(NSString *)appointmentName 
                           description:(NSString *)appointmentDescription 
                                 eDate:(NSDate *)appointmentEndDate
{
    NSManagedObjectContext *managedObjectContext = [[CoreDataManager sharedManager] managedObjectContext];
    AppointmentObject *newAppointmentObject = [NSEntityDescription insertNewObjectForEntityForName:AppointmentObjectEntityName
                                                                            inManagedObjectContext:managedObjectContext];    
    newAppointmentObject.appointmentName = appointmentName;
    newAppointmentObject.appointmentDescription = appointmentDescription;
    newAppointmentObject.appointmentDate = [appointmentDate earlierDate:appointmentEndDate];
    newAppointmentObject.appointmentEndDate = [appointmentEndDate laterDate:appointmentDate];   
}

-(void)deleteAppointmentObject:(AppointmentObject *)appointmentObject triggeredByUser:(BOOL)byUser{
    NSManagedObjectContext *managedObjectContext = [[CoreDataManager sharedManager]   managedObjectContext];
    [managedObjectContext deleteObject:appointmentObject];
}

But all kind of crazy stuff is happening which makes my app crash with "SICBART" message:

2010-10-13 17:35:04.630 didacta[109:307] Serious application error.  Exception was      caught during Core Data change processing. 
This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  
-[CALayer controllerWillChangeContent:]: unrecognized selector sent to instance 0x19f150 with userInfo (null)
2010-10-13 17:35:05.118 didacta[109:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer controllerWillChangeContent:]: unrecognized selector sent t开发者_如何学Co instance 0x19f150'

errors appear while doing this:

  • creating new Appointment and pressing "Done" (should trigger creation and pop overview)
  • changing appointments and pressing "Done" (should send changes and pop overview)
  • tapping on an appointment in overview ( should pop create/edit view and hand over values)
  • deleting an item

sometimes I can even delete an appointment but then the order of the items in the tableview is somehow gotten twisted so the index of the tableview isn't pointing to the index of the appointment anymore.


Right.

-[CALayer controllerWillChangeContent:]: unrecognized selector sent to instance 0x19f150 with userInfo (null)

That's your error. You have an NSFetchedResultsController whose delegate is a CALayer. This sounds like the original delegate was deallocated and a CALayer was allocated using the same region of memory. The fix is to find the offending -dealloc and add something like self.myFetchedResultsController.delegate = nil; self.myFetchedResultsController = nil; assuming you're using properties.

You can sometimes help debugging things like this by enabling zombies (go to Project → Edit Current Executable or so, select Environment, add the NSZombieEnabled environment variable, and set its value to "YES" or so; uncheck the checkbox when you've finished debugging). Zombies cause an exception when a message is sent to a deallocated object. (Zombies are not deallocated by default, so your application will effectively leak; remember to uncheck the checkbox!).


"unrecognized selector" makes it sound like maybe your data model doesn't contain some of the Entity attributes that you're trying to use. For example, maybe you're trying to set an attribute of the object that doesn't exist.

Try creating a breakpoint at newAppointmentObject.appointmentName = appointmentName; and step through it to see at what point the error occurs.

0

精彩评论

暂无评论...
验证码 换一张
取 消