我正在开发一个应用程序,它使用由 MagicalRecord 管理的数据库。应用程序显示用户可以添加点击 + 按钮的名称。 + 按钮打开一个 UIAlert,用户可以在其中键入一个新名称,然后点击确定名称将添加到数据库中。 麻烦的是,每次用户添加新名称时,都必须重新加载表以显示新名称。 为了重新加载表,我导入了 CoreDataHelper 并且我正在使用此方法:(我在那里找到了所有内容:https://github.com/kgudger/AssignLine)
@property (strong, nonatomic) NSMutableArray * eventiArray; // Array which populate table
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
-(void)readDataForTable {
_eventiArray = [CoreDataHelper getObjectsForEntity:@"Entity" withSortKey:@"nomeEvento" andSortAscending:YES andContext: _managedObjectContext];
[self.tableView reloadData]; }
// (Entity is the name of NSManagedObject SubClass)
// (nomeEvento is the name of NSString in NSManagedObject SubClass)
运行时,它崩溃说 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Entity''
但我不明白原因,有人可以帮助我吗?谢谢!!!
最佳答案
我的建议是使用 MagicalRecord 加载数据。
-(void)readDataForTable {
self.eventiArray = [YourEntity MR_findAllSortedBy:@"nomeEvento" ascending:YES inContext:[NSManagedObjectContext MR_defaultContext]];
[self.tableView reloadData];
}
如果你想在上下文中使用它
[YourEntity MR_findAllSortedBy:@"nomeEvento" ascending:YES inContext:self.managedObjectContext];
或
[YourEntity MR_findAllSortedBy:@"nomeEvento" ascending:YES];
关于ios - 如何使用readDataForTable方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19431670/