0

I am getting [__NSCFData controllerWillChangeContent:]: unrecognized selector sent to instance 0x7cc61f20' when try to update database. I have tried many solution in Stack overflow but none of them gave me solution. Please help before make any down vote, I am really stuck at this point.

My problem:

I have a table view which loads data from core data, when i click on each cell it will go to another view controller and it also load data from core data. There is a button for creating new database entry. When i click on that button it will create new entry for data base.and after that when i switch back to main view app getting crashed [__NSCFData controllerWillChangeContent:]: unrecognized selector sent to instance 0x7cc61f20'

I have tried self.fetchedresultController = nil, but i t still happening. Please help, idont know how to solve this error? is there any other method?

  2015-02-24 16:47:42.531 Inxed[4489:100349] *** Terminating app due to              uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData   controllerWillChangeContent:]: unrecognized selector sent to instance 0x7cc61f20'
   *** First throw call stack:
 (
0   CoreFoundation                      0x03687946 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x03310a97 objc_exception_throw + 44
2   CoreFoundation                      0x0368f5c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3   CoreFoundation                      0x035d83e7 ___forwarding___ + 1047
4   CoreFoundation                      0x035d7fae _CF_forwarding_prep_0 + 14
5   CoreData                            0x01531366 __77-[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:]_block_invoke + 2166
6   CoreData                            0x01530adc -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 140
7   Foundation                          0x02ebec49 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
8   CoreFoundation                      0x036524a4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
9   CoreFoundation                      0x0354003b _CFXNotificationPost + 3051
10  Foundation                          0x02eae246 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
11  CoreData                            0x0141f4d3 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 83
12  CoreData                            0x014bf54f -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 367
13  CoreData                            0x0141a1a6 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 3190
14  CoreData                            0x0141dc7a -[NSManagedObjectContext save:] + 154
15  Inxed                               0x002db0c7 -[IXDataBaseManager updateThreadEnityForCreateThreadWithDetails:] + 27735
16  Inxed                               0x0027708d -[IXNetworkDataManager manageThreadWithDetails:] + 3005
17  Inxed                               0x00286982 -[IXNetworkDataManager receiveDidFinishResponse:] + 9234
18  libobjc.A.dylib                     0x03326771 -[NSObject performSelector:withObject:] + 70
19  Inxed                               0x0018348b -[ASIHTTPRequest reportFinished] + 171
20  libobjc.A.dylib                     0x03326771 -[NSObject performSelector:withObject:] + 70
21  Foundation                          0x02f12f20 __NSThreadPerformPerform + 330
22  CoreFoundation                      0x035ab1df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23  CoreFoundation                      0x035a0ced __CFRunLoopDoSources0 + 253
24  CoreFoundation                      0x035a0248 __CFRunLoopRun + 952
25  CoreFoundation                      0x0359fbcb CFRunLoopRunSpecific + 443
26  CoreFoundation                      0x0359f9fb CFRunLoopRunInMode + 123
27  GraphicsServices                    0x0492424f GSEventRunModal + 192
28  GraphicsServices                    0x0492408c GSEventRun + 104
29  UIKit                               0x01ce78b6 UIApplicationMain + 1526
30  Inxed                               0x0024578d main + 141
31  libdyld.dylib                       0x04078ac9 start + 1
32  ???                                 0x00000001 0x0 + 1
)

detailedviewcontroller.m

 -(void)replySolicitation
 {

   IXConfirmFeedbackPage *loscr = [[IXConfirmFeedbackPage alloc] initWithNibName:@"IXConfirmFeedbackPage" bundle:nil];








  BOOL isNetworkAvailable=[[IXNetworkDataManager sharedNetworkDataManager] checkForNetworkConnection];
//ThreadInfo *info=[self selectedThreadInfo];


if(isNetworkAvailable)
{
    ThreadInfo *threadInfo=[self selectedThreadInfo];
    NSString *feedback=threadInfo.threadMessage;
    NSString *toAddress=threadInfo.receiverEmail;

    NSDate *replyDateInfo = [NSDate date];
    self.commentTextView.text=[self.commentTextView.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *loginUser=[[NSUserDefaults standardUserDefaults] valueForKey:@"currentUser"];

    if(self.commentTextView.text.length!=0)
    {
        NSMutableDictionary *dict=[[IXNetworkDataManager sharedNetworkDataManager] AESEncryptionForMessage:feedback];

        UserInfo *info=[[IXDataBaseManager sharedNetworkDataManager] retrieveCurrentUserDetailsForUser:loginUser];
        if(info!=nil)
        {
            NSInteger randomNumber = (arc4random()%LONG_MAX)+RANDOM_MIN_NUMBER;
            NSNumber *seqNumber=[NSNumber numberWithInteger:randomNumber];

            NSMutableDictionary *paramsDic=[[NSMutableDictionary alloc] init];

//[paramsDic setObject:threadInfo.threadMessage forKey:@"threadMessage"];
            [paramsDic setObject:seqNumber forKey:@"sequence_number"];
            [paramsDic setObject:info.sessionID forKey:@"sid"];
            [paramsDic setObject:loginUser forKey:@"email"];
            [paramsDic setObject:[dict valueForKey:@"key"] forKey:@"key"];
            [paramsDic setObject:[dict valueForKey:@"secret"] forKey:@"secret"];
            [paramsDic setObject:[dict valueForKey:@"secret_seed"] forKey:@"secret_seed"];
            [paramsDic setObject:[dict valueForKey:@"msg"] forKey:@"msg"];
            [[IXNetworkDataManager sharedNetworkDataManager] startLoadingWithOutUI];
            [paramsDic setObject:toAddress  forKey:@"to"];
            [paramsDic setObject:threadInfo.solicitationID  forKey:@"solicitation"];
            [paramsDic setObject:[NSString stringWithFormat:@"%@",seqNumber] forKey:@"thread"];
            [paramsDic setObject:feedback  forKey:@"threadDescription"];

            //[[IXNetworkDataManager sharedNetworkDataManager] createThreadWithDetails:paramsDic];

            loscr.selectedMessageArray=paramsDic;

            CATransition* transition = [CATransition animation];
            transition.duration = .25;
            transition.type = kCATransitionFade;
            [self.view.window.layer addAnimation:transition forKey:kCATransition];
            [self presentViewController:loscr animated:NO completion:nil];
            loscr=nil;

            [self closeCommentsView];


           // [paramsDic setObject:replyDateInfo  forKey:@"replyDate"];
            //[self manageThreadWithDetails:paramsDic];
        }
    }
    else
    {
        UIAlertView *errorAlert=[[UIAlertView alloc]initWithTitle:nil message:@"Please enter feedback" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
    }

}
else
{
    [self closeCommentsView];

    UIAlertView *errorAlert=[[UIAlertView alloc]initWithTitle:nil message:@"No network connection" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

 }

secondviewcontroller.m

   -(void)manageThreadWithDetails:(NSMutableDictionary *)inDictionary
 {
NSLog(@"manageThreadWithDetails==%@",inDictionary);
NSDate *threadDate=[NSDate date];
if([[inDictionary allKeys] containsObject:@"created_at"])
{
    NSTimeInterval timeInterval=[[inDictionary valueForKey:@"created_at"] doubleValue];
    threadDate=[[IXNetworkDataManager sharedNetworkDataManager] retrieveDateFromInterval:timeInterval];

}
NSString *loginUser=[[NSUserDefaults standardUserDefaults] valueForKey:@"currentUser"];

UserInfo *info=[[IXDataBaseManager sharedNetworkDataManager] retrieveCurrentUserDetailsForUser:loginUser];
if(info!=nil)
{

    NSInteger randomNumber = (arc4random()%LONG_MAX)+RANDOM_MIN_NUMBER;
    NSNumber *seqNumber=[NSNumber numberWithInteger:randomNumber];

    int randomIndex = [[IXNetworkDataManager sharedNetworkDataManager] getIndexForColorImageForTab:@"OUT"];//arc4random() % COLORCODE_COUNT;
    [inDictionary setObject:[NSNumber numberWithInt:randomIndex] forKey:@"colorCode"];

    [inDictionary setObject:[NSNumber numberWithBool:YES] forKey:@"isSender"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isReceiver"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isPollSender"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isRequester"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isProvider"];

    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isPoll"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isQuiz"];

    [inDictionary setObject:loginUser forKey:@"userEmail"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"liked"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"disliked"];
    [inDictionary setObject:[NSNumber numberWithBool:YES] forKey:@"isPending"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isSystemMessage"];
    [inDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"isAnyReceiverActivity"];
    [inDictionary setObject:[NSString stringWithFormat:@"%@",[inDictionary valueForKey:@"sequence_number"] ]forKey:@"thread"];
   // [inDictionary setObject:@"hey sder" forKey:@"threadDescription"];


        //    NSString *toAddress=[_toRecipients objectAtIndex:0];
        //    [inDictionary setObject:toAddress forKey:@"receiverEmail"];




    //[inDictionary setObject:_toRecipients forKey:@"to"];
    [inDictionary setObject:threadDate forKey:@"threadDate"];
    [inDictionary setObject:threadDate forKey:@"receivedDate"];

    [[IXDataBaseManager sharedNetworkDataManager] insertToThreadEntityWithData:inDictionary];
}
[IXNetworkDataManager sharedNetworkDataManager].delegate=nil;


}
Nicolas S
  • 5,325
  • 3
  • 29
  • 36
Jan
  • 1,744
  • 3
  • 23
  • 38
  • Any idea about this error? – Jan Feb 24 '15 at 11:54
  • Where are you calling self.fetchedresultController = nil? – Fawad Masud Feb 24 '15 at 11:56
  • - (void)viewWillDisappear:(BOOL)animated in detailedviewcontroller – Jan Feb 24 '15 at 12:01
  • what is the cause of this error? – Jan Feb 24 '15 at 12:02
  • In android i have done as simple, but ios same logic not working. – Jan Feb 24 '15 at 12:02
  • try setting all properties to nil in viewWill disappear. I think some property is not releasing as view disappears. – Fawad Masud Feb 24 '15 at 12:08
  • What are the other properties? iam newbie in ios. can you give me some examples? – Jan Feb 24 '15 at 12:12
  • like anything with retain or strong in header file should be made nil. – Fawad Masud Feb 24 '15 at 12:15
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Feb 24 '15 at 13:33
  • Two things that might help. One is that that you're doing this on threads by the look of the method names. Core Data can behave oddly when used concurrently. Secondly there's reference to a 3rd party network database manager in there, which might be the cause. Are you mainly from an Android background? I understand that threads are a large part of development there, we tend to abstract away to queues and for Core Data that can still be a problem. If you're trying to implement a pattern from Android in iOS then you're going to run into issues. – Cocoadelica Feb 24 '15 at 13:59
  • Thanks for the information, I am basically android. – Jan Feb 24 '15 at 17:03

1 Answers1

0

What you likely need to do is set the fetchedresultController's delegate property to nil - not the controller itself.

What's likely happening is that after your viewController gets dismissed, the NSFetchedResultsController's delegate has a weak reference to it that is not getting nil'd out. Then, the memory space gets re-used and all of a sudden controllerWillChangeContent gets called on some totally random object.


I don't think this is a "Threading" issue as the thread terms in your sample code appear to be referring to conversational threads (like on a forum).


In addition, it may make your life a little easier to use some modern Objective-C syntax like the following:

NSMutableDictionary *paramsDict = [@{
    @"threadMessage":threadInfo.threadMessage,
    @"sequence_number":seqNumber,
    @"sid":info.sessionID,
    @"secret":dict[@"secret"],
    // etc.
} mutableCopy];

and

[inDictionary setObject:@YES forKey:@"isSender"];
Stephen Furlani
  • 6,794
  • 4
  • 31
  • 60