开发者

fetchresultscontroller issue or managed object context?

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];
}


[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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜