我的模型类中有一个FetchRequest
名为ContentManager
. 它获取了相当多的数据,因此在完成之前屏幕是空白的。在ViewController
显示获取结果的那个中,我想显示一个加载指示器,所以我想在FetchRequest
完成时获得一个回调并将其传递给ViewController
以停止加载指示器。这可能吗?
这是FetchRequest
课堂上的内容ContentManager
:
- (NSArray*)recipesForMagazine
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSString* path = [[NSBundle mainBundle] pathForResource:@"magazine_recipe_guids" ofType:@"plist"];
NSArray* recipeGuids = [NSArray arrayWithContentsOfFile:path];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"guid IN %@",recipeGuids];
[request setPredicate:predicate];
NSSortDescriptor* sort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];
[sort release];
NSError* error = nil;
NSArray* fetchResults = [managedObjectContext executeFetchRequest:request error:&error];
[request release];
return fetchResults;
}
这里我设置在ViewController
self.magazineRecipes = [[ContentManager defaultManager] recipesForMagazine];
我想像这样设置 fetchrequest 方法:
- (NSArray*)recipesForMagazine:(void (^)(BOOL success))block
什么的,所以在viewcontroller
我可以这样称呼它
self.magazineRecipes = [[CTContentManager defaultManager] recipesForMagazine:^(BOOL success) {
if (success) {
//stop activity indicator view
}
}];
我不知道我的想法是否正确,提前感谢您的帮助!