0

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 to 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.

Amandir
  • 679
  • 1
  • 7
  • 20

2 Answers2

3

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!).

tc.
  • 33,468
  • 5
  • 78
  • 96
  • I searched the code again, but there is no place where I deallocate the delegate. But now I finally I can reproduce an error: My appointments are sorted by date. When I change the date of an Item, the Tableview stops refreshing for some reason. But the order of the Items I get by the fetchedResultscontroller still is correct (with the item with changed date at right place). I update the Tableview by "reloaddata" at viewWillAppear. Could this be a trace? – Amandir Oct 14 '10 at 16:17
  • To be more precise: the CellForRow isn't called anymore. Not by delegate and not by reloadData. when I close the App and start it again. the appointments are in right order and the update of the tableView is working again. – Amandir Oct 14 '10 at 16:54
  • He means you have either deallocated the fetched results controller's delegate or you have assigned the CALayer as the delegate. When you make a change to the data, the CALayer receives the delegate error. If the error is consistent, you have assigned a CALayer as the delegate somewhere in the code. – TechZen Oct 15 '10 at 21:42
  • Oh, man, I've been having a CoreData issue from some code I inherited and this was the problem. I was getting all kinds of random issues, but occasionally I would get this one. This was thanks to MagicalRecord, that has some method that requires a delegate. But magical record does not handle the deallocation of the delegate. This happened to me even with ARC, mind you. – HotFudgeSunday Sep 07 '16 at 12:48
-2

"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.

Nimrod
  • 5,168
  • 1
  • 25
  • 39