Đây là mã cho toggleAddProject, mã Dữ liệu chính gần như giống như trong mẫu CoreDataBooks của Apple, tuy nhiên khi tôi nhấp vào nút thêm, ứng dụng gặp sự cố với entityForName: could not locate an NSManagedObjectModel for entity name 'Project'
trên dòng bắt đầu với newProjectController.project
không thể định vị một NSManagedObjectModel cho tên thực thể
-(IBAction)toggleAddProject
{
NewProjectViewController *newProjectController = [[[NewProjectViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
// Create a new managed object context for the new project -- set its persistent store coordinator to the same as that from the fetched results controller's context.
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
self.addingManagedObjectContext = addingContext;
[addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
newProjectController.project = (Project *)[NSEntityDescription insertNewObjectForEntityForName:@"Project" inManagedObjectContext:addingContext];
[addingContext release];
UINavigationController *addNewNavigationController = [[UINavigationController alloc] initWithRootViewController:newProjectController];
[self.navigationController presentModalViewController:addNewNavigationController animated:YES];
[addNewNavigationController release];
}
Mọi thứ đã được tổng hợp, thực thể Dự án tồn tại. Tôi không thể hiểu tại sao nó bị treo. Hầu hết mọi người dường như để có thể khắc phục lỗi này bằng cách chèn đoạn mã sau hoặc trong các phương pháp riêng của mình, hoặc trong viewDidLoad:
if (managedObjectContext == nil)
{
managedObjectContext = [(CoreDataBooksAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
Khi sửa đổi cho đại biểu ứng dụng của tôi nó làm cho không có sự khác biệt. Cảm ơn vì bất kì sự giúp đỡ.
Tôi đã kết thúc việc tiếp cận sự khác biệt này và lỗi này hiện không xuất hiện. Nhưng cảm ơn anyway, không có lỗi chính tả trong mã của tôi nhưng tôi chắc chắn nó là một trong những thứ khác mà bạn đã liệt kê, rất có thể là moc là nil. – ChrisJP
4. là vấn đề trong trường hợp của tôi –