我能够从这段代码中获取Managed对象上下文。它带给我另一个问题。我有2个VIEW CONTROLLERS和1个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'
已编辑并添加了相关代码..
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 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];
}
答案 0 :(得分:0)
[getUserDetailsService setDelegate:自];
这可能是你的bugger,但是直到我至少看到所涉及的所有类的标题都不确定。
此外,将Logs放入所有Dealloc函数中,看看是否有些东西过早消失。
干杯
答案 1 :(得分:0)
你的问题是,在某些时候,你已经为NSString换了一个NSManagedObject。当上下文保存时,它会将objectID
消息发送到它认为是托管对象的消息,但由于它是一个字符串对象,因此字符串对象不理解该消息。
最有可能的是,错误实际上是在您指定关系的自定义NSManagedObject子类中。您已设置字符串而不是托管对象。