gpt4 book ai didi

ios - AFIncrementalStore viewDidLoad 中的空结果

转载 作者:行者123 更新时间:2023-11-29 03:30:24 24 4
gpt4 key购买 nike

使用 AFIncrementalStore,我尝试在 Controller 加载时获取实体的数据集。我在以前的 Controller 上有类似的工作,并尝试遵循该模式:

- (void)viewDidLoad
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"ItemCategory"];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(localizedStandardCompare:)]];
fetchRequest.returnsObjectsAsFaults = NO;

_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[appDelegate managedObjectContext] sectionNameKeyPath:nil cacheName:nil];
_fetchedResultsController.delegate = self;
[_fetchedResultsController performFetch:nil];
}

然后,我尝试获取该数据来填充表格单元格中的 UIPickerView:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *rows = [_fetchedResultsController fetchedObjects];
NSLog(@"%@",rows);
...}

但是 fetchedObjects 返回一个空数组。我获取数据的唯一方法是在调用“fetchedObjects”之前重新获取,如下所示:

_fetchedResultsController.fetchRequest.resultType = NSManagedObjectResultType;
[_fetchedResultsController performFetch:nil];

但随后我又不必要地再次访问服务器。据我所知,两次获取都以完全相同的方式执行。那么为什么在数据填满之前需要进行第二次读取呢?

我的理论是,第二次获取实际上以某种方式使第一次获取的数据可用,而不是实际存储新数据,但我对 CoreData 的理解有点太不稳定,无法准确确定发生了什么。感谢您帮我解决这个问题!

编辑我想说的是,我尝试了类似问题的解决方案但无济于事:https://stackoverflow.com/a/11334792/380643

最佳答案

你记得在你的 table 上做一个 reloadData 吗?

关于ios - AFIncrementalStore viewDidLoad 中的空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19885545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com