我正在使用RestKit从特定的网址加载对象。在tableView中进行映射和显示。好的,它有效。但是当我没有互联网连接时,它会加载最后加载的对象的内容。奇怪的是:
它并没有真正加载最后加载的对象。当我加载对象“1”时,关闭应用程序,再次运行它以加载对象“2”,然后再次关闭,关闭连接并运行,它显示对象1的内容。即使我清理上下文加载对象“2”,然后“1”,关闭连接并运行,它再次显示对象“1”的内容!似乎对象“1”具有某种“优先级”。
我在做什么:
- (void)dataDownload
{
[self showLoading:YES];
RKObjectManager* objectManager = [RKObjectManager sharedManager];
[objectManager loadObjectsAtResourcePath:@"my-url" delegate:self block:^(RKObjectLoader* loader) {
loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Conteudo class]];
}];
}
- (void) loadDatabase
{
NSFetchRequest* request = [Conteudo fetchRequest];
NSSortDescriptor* descriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:descriptor]];
self.conteudo = [Conteudo organizeData:[Conteudo objectsWithFetchRequest:request]];
}
`
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
[self showLoading:NO];
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"LastUpdatedAt"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSArray *result = objects;
if(result != nil){
self.conteudo = [Conteudo organizeData:result];
[[NSManagedObject managedObjectContext] save:nil];
}
else
[self loadDatabase];
[self.tableView reloadData];
}
`
感谢帮助=]