0
我想過濾一些管理對象。結果雖然是zip。爲什麼這個獲取請求不返回
過濾器是「名稱」。名稱是根視圖提供給此詳細視圖的元素。 名稱記錄確定:
[48582:2754928] name: To Be
[48582:2754928] predicate: name == @"name"
name = [self.detailItem valueForKey:@"name"];
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
和FetchResultsController如下:
NSError *error = nil;
name = [self.detailItem valueForKey:@"name"];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"VerbEntity" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
predicate = [NSPredicate predicateWithFormat:@"name == %@",@"name"];
NSLog(@"name: %@", name);
fetchRequest.predicate = predicate;
NSLog(@"predicate: %@", predicate);
// Create the sort descriptors array.
NSArray *sortDescriptorArray = nil;
// Declare sort descriptors
NSSortDescriptor *sortDescriptorPrimary = nil;
sortDescriptorPrimary = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
// Set sort descriptor array
sortDescriptorArray = @[sortDescriptorPrimary];
// Apply sort descriptors to fetch request
[fetchRequest setSortDescriptors:sortDescriptorArray];
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"fetchedObjects count: %lu", (unsigned long)fetchedObjects.count);
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
做任何事情脫穎而出靠不住?謝謝你的幫助。
沒有謂詞,你的獲取返回的東西嗎?如果name是一個'NSString',那麼使用'@「名稱LIKE%@」'怎麼辦?你不是想把'@「name ==%@」,@「name」'改成'@「name ==%@」,name',這可能是一個錯誤,並解釋了爲什麼你沒有找到任何東西在你的提取? – Larme 2014-09-24 14:37:41
如果初始化提取請求的方式不同,會發生什麼情況?也許試試 [NSFetchRequest fetchRequestWithEntityName:@「VerbEntity」]; 另外,什麼是_fetchedResultsController?一個NSFetchedResultsController?如果是這樣,你需要在其上設置NSFetchRequest對象。 – 2014-09-24 15:33:20
謝謝大家。你的答案組合解決了這個問題。 – 2014-09-24 18:32:19