fetchresultscontroller问题或受管对象上下文? [英] fetchresultscontroller issue or managed object context?

查看:292
本文介绍了fetchresultscontroller问题或受管对象上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从这段代码中获取Managed对象上下文。它带给我另一个问题。我有2个查看控制器和1个NSObject

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 / li>
  3. FetchProcessor(NSObject)

顺序地,Userlookup vc首先加载, Userlookup设置VC +一个文本框和UiButton。当应用程序加载,我点击SETTINGS uibutton,事情工作正常...但是,当我做搜索(FetchProcessor),然后加载设置,它给我错误(请检查下面)

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:

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






现在@implementation GetUserDetailsS​​OAPService


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


NOW @interface TCodeSettings : NSObject

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






NOW @interface UserLookupSettings:UITableViewController


NOW @interface UserLookupSettings : UITableViewController

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






推荐答案

这里的问题是,在某些时候,你已经为NSString换出了一个NSManagedObject。当上下文保存时,它将 objectID 消息发送到它认为是受管对象的消息,但由于它是一个字符串对象,所以字符串对象不能理解消息。

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.

最有可能的是,错误实际上是在一个自定义的NSManagedObject子类中分配关系。您已设置字符串而不是管理对象。

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.

这篇关于fetchresultscontroller问题或受管对象上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆