我有这个功能:
- (void)initFetchRequest
{
NSManagedObjectContext *context = self.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Shindy" inManagedObjectContext:self.managedObjectContext];
// Configure the request's entity, and optionally its predicate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"details" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:request
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil];
NSError *error = nil;
[self.managedObjectContext executeFetchRequest:request error:&error];
[fetchedResultsController performFetch:&error];
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
在我的viewDidLoad
方法中使用以下内容
NSURL *url = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
document = [[UIManagedDocument alloc] initWithFileURL:url];
self.managedObjectContext = document.managedObjectContext;
[self initFetchRequest];
最后,这在我的cellForRowAtIndexPath
Shindy *shindy = [fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = shindy.details;
数据是从另一个控制器输入的,当我回到这个控制器时,UITableViewController
它没有更新。
我在这里想念什么?