我可以使用一些幫助來調試[context deleteObject:loan];
命令上收到的EXC_BAD_ACCESS
錯誤。在下面的代理方法中收到錯誤:核心數據上的訪問錯誤deleteObject
- (void)didCancelNewLoan:(Loan *)loan {
// save the context
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:loan]; // *** EXC_BAD_ACCESS here ***
// This method is called from a the following method in a second class:
- (IBAction)cancel:(id)sender {
[delegate didCancelNewLoan:self.loan];
}
// The loan ivar is created by the original class
// in the below prepare for Segue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"NewLoan"]) {
UINavigationController *navController = (UINavigationController *)[segue destinationViewController];
LoanViewController *loanView = (LoanViewController *)[[navController viewControllers] lastObject];
loanView.managedObjectContext = self.managedObjectContext;
loanView.delegate = self;
loanView.loan = [self createNewLoan];
loanView.newLoan = YES;
}
// Finally, the loan is created in the above
// method's [self createNewLoan] command:
- (NSManagedObject *)createNewLoan {
//create a new instance of the entity managed by the fetched results controller
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidstring = CFUUIDCreateString(NULL, uuid);
//NSString *identifierValue = (__bridge_transfer NSString *)uuidstring;
[newManagedObject setValue:(__bridge_transfer NSString *)uuidstring forKey:@"identifier"];
CFRelease(uuid);
CFRelease(uuidstring);
NSError *error;
[self.fetchedResultsController performFetch:&error];
NSLog(@"%i items in database", [[self.fetchedResultsController fetchedObjects] count]);
return newManagedObject;
}
感謝您查看上述方法。
感謝您的反饋。我嘗試了一些建議。當在收到該操作的視圖控制器中運行上面的代碼時,我得到相同的錯誤。我打開殭屍,並獲得更多的錯誤信息:「[CFString保留]:消息發送到解除分配的實例...」,是的,你是正確的數據顯示在tableview中,我已經在接收中實現NSFetchedResultsController委託方法視圖控制器。 – Jack 2012-03-19 14:51:47
你可以嘗試'__bridge'你的CFString而不是'__bridge__transfer'嗎?看起來您的CFString對象正在儘快發佈。 – Rog 2012-03-19 19:30:53
或者保留原樣,根據我對文檔的理解,不要發佈'uuidstring',因爲ARC正在爲你做這件事。 – Rog 2012-03-19 19:36:09