fetchresultscontroller issue or managed object context?

假装没事ソ 提交于 2020-01-06 19:56:33

问题


Reference POST:

Core Data - Basic Questions

I am able to get the Managed object context from this piece of code. It bring me to another question. I have 2 VIEW CONTROLLERS and 1 NSObject

  1. Userlookup (VC)
  2. UserlookupSettings(VC)
  3. FetchProcessor (NSObject)

In sequence, Userlookup vc loads first and has a button to load the Userlookupsettings VC + a textbox and UiButton. When the app is loaded and I hit the SETTINGS uibutton, things work fine... however, when i do the search (FetchProcessor) and then load the settings, it gives me error (check below please) for


 if (![[managedObject managedObjectContext] save:&error]) {
        NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],[error localizedDescription]);
        exit(-1);  // Fail  
    }

ERROR:


2010-09-11 03:10:47.148 SAPBasis[975:207] *** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830
2010-09-11 03:10:47.170 SAPBasis[975:207] Serious application error.  Exception was caught during Core Data change processing: *** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830 with userInfo (null)
2010-09-11 03:10:47.170 SAPBasis[975:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830'

EDITED and added relevant codes..

UserLookup:

-(void) searchUser{
        getUserDetailsService=[[GetUserDetailsSOAPService alloc]init]; // where AbstractServiceProvider *getUserDetailsService; and @interface GetUserDetailsSOAPService : AbstractServiceProvider
        [getUserDetailsService setSettingPreference:settings];
        [settings release];
        [getUserDetailsService setDelegate:self];
        RequestDO * request = [[RequestDO alloc]init];
        request.userID=userIdInputField.text;
        [getUserDetailsService setRequestDO:request];
        [request release];
        NSManagedObjectContext *context = self.referringObject;
        [getUserDetailsService setReferringObject:context];
        [getUserDetailsService execute]; // This is the user search function.
        [getUserDetailsService release];
}

-(void) editUserLookupSettings{
    UserLookupSettings *viewVC = [[UserLookupSettings alloc] initWithNibName:@"UserLookupSettings" bundle:nil];
    viewVC.title =  @"Settings for User Lookup";
    NSManagedObjectContext *context = self.referringObject;
    viewVC.referringObject = context;
    [self.navigationController pushViewController:viewVC animated:YES];
    // Manage memory
    [viewVC release];
}

NOW @implementation GetUserDetailsSOAPService

-(void)execute{
    TCodeSettings *fetch = [[TCodeSettings alloc] init]; // Where @interface TCodeSettings : NSObject <NSFetchedResultsControllerDelegate>
    fetch.referringObject = self.referringObject;
    resultsOfSettings = [fetch initCode]; // Code details given below. I think so is causing the error when this is called.
    [fetch release];
    self.userData = [[NSMutableDictionary alloc] init];
    self.previewData = [[NSMutableArray alloc] init];

    // Creates new Request object and sets its url
    NSString *URLReq = [self.settingPreference getSOAPPrefix];
    URLReq=[URLReq stringByAppendingString:@"Z_USERLOOKUPWS"];
    URLReq=[URLReq stringByAppendingString:[self.settingPreference getSOAPSuffix]];

    theRequest=[NSMutableURLRequest 
                requestWithURL:[NSURL URLWithString:URLReq]
                cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                timeoutInterval:30.0];

    // Setting specific SOAP headers
    // For SOAP content type is text/xml
    .
    .
    .
    [self makeReqest]; // AbstractServiceProvider we have makeRequest function and it works fine..
}

NOW @interface TCodeSettings : NSObject

- (NSFetchedResultsController *)initCode{
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
        // Handle the error
    }else {
        return fetchedResultsController;
    }
}

NOW @interface UserLookupSettings : UITableViewController

- (void)viewDidLoad {   
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
        // Handle the error
    }
    [super viewDidLoad];
}


回答1:


[getUserDetailsService setDelegate:self];

this could possibly be your bugger but this is not sure until I see at least the headers for all classes involved.

And also, put Logs in all of your Dealloc functions to see if something goes away prematurely.

Cheers




回答2:


Your problem here is that at some point, you have swapped out a NSManagedObject for a NSString. When the context goes to save, it sends the objectID message to what it thinks is a managed object but since it is a string object, the string object does not understand the message.

Most likely, the error is actually in a custom NSManagedObject subclass where you assign a relationship. You've set a string instead of managed object.



来源:https://stackoverflow.com/questions/3689022/fetchresultscontroller-issue-or-managed-object-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!