0

参考帖子:

核心数据 - 基本问题

我能够从这段代码中获取托管对象上下文。它让我想到另一个问题。我有 2 个视图控制器和 1 个 NSObject

  1. 用户查找 (VC)
  2. 用户查找设置(VC)
  3. FetchProcessor (NSObject)

按顺序,Userlookup vc 首先加载,并且有一个按钮来加载 Userlookupsettings VC + 一个文本框和 UiButton。当应用程序加载并且我点击 SETTINGS uibutton 时,一切正常......但是,当我进行搜索(FetchProcessor)然后加载设置时,它给了我错误(请在下面检查)


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

错误:


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'

编辑并添加了相关代码..

用户查找:

-(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

-(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..
}

现在@interface TCodeSettings:NSObject

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

现在@interface UserLookupSettings:UITableViewController

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

4

2 回答 2

0

[getUserDetailsS​​ervice setDelegate:self];

这可能是你的错误,但在我至少看到所有涉及的类的标题之前,这还不确定。

此外,将 Logs 放入您的所有 Dealloc 函数中,以查看某些内容是否过早消失。

干杯

于 2010-09-11T02:43:59.533 回答
0

您的问题是,在某些时候,您已经将 NSManagedObject 换成了 NSString。当上下文保存时,它会将objectID消息发送到它认为是托管对象的对象,但由于它是一个字符串对象,因此字符串对象不理解该消息。

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

于 2010-09-11T19:14:30.857 回答