私にはMyClass:UITableViewController
いくつNSFetchedResultsController
かの問題があります:MyClassの新しいインスタンスを作成すると、fetchedResultsControllerは私に空を返しますfetchedObjects
。しかし、このクラスの最初のインスタンスでは、すべてが大丈夫です...
私が間違っているのは何ですか?
managaedCondextおよびその他の必要な変数を使用すると、すべて問題ありません(つまり、エラーは発生せず、結果は空になります)
MyClass.h
@interface MyClass : UITableViewController <UISearchDisplayDelegate, NSFetchedResultsControllerDelegate>
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@end
MyClass.m
@implementation MyClass
@synthesize fetchedResultsController = _fetchedResultsController;
......
- (NSFetchedResultsController *)newFetchedResultsControllerWithSearch:(NSString *)searchString
{
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *callEntity = [NSEntityDescription entityForName:@"Entity" inManagedObjectContext:_managedObjectContext];
[fetchRequest setEntity:callEntity];
NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"attr == %@", _value];
NSMutableArray *predicateArray = [NSMutableArray array];
if(searchString.length)
{
// your search predicate(s) are added to this array
[predicateArray addObject:[NSPredicate predicateWithFormat:@"title CONTAINS[cd] %@", searchString]];
// finally add the filter predicate for this view
if(filterPredicate)
{
filterPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, [NSCompoundPredicate orPredicateWithSubpredicates:predicateArray], nil]];
}
else
{
filterPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:predicateArray];
}
}
[fetchRequest setPredicate:filterPredicate];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
[sortDescriptor release];
[fetchRequest setSortDescriptors: sortDescriptors];
[sortDescriptors release];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[DataManager shared].managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
aFetchedResultsController.delegate = self;
[fetchRequest release];
NSError *error = nil;
if (![aFetchedResultsController performFetch:&error])
{
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return aFetchedResultsController;
}
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil)
{
return _fetchedResultsController;
}
_fetchedResultsController = [self newFetchedResultsControllerWithSearch:nil];
return [[_fetchedResultsController retain] autorelease];
}
他の方法は標準であり、追加はありません...
最初の瞬間は(すべてが機能します!):
MyClass *myClass = [[[MyClass alloc] initWithNibName:@"MyClass" bundle:nil] autorelease];
myClass.tabBarItem.image = [UIImage imageNamed:@"myClass"];
myClass.title = NSLocalizedString(@"myClass", @"myClass");
UINavigationController *myClassNavigationController = [[[UINavigationController alloc] initWithRootViewController:myClass] autorelease];
次に、クラスのインスタンスを表示しようとします。
MyClass *myClass1 = [[MyClass alloc] initWithNibName:@"MyClass" bundle:nil];
myClass1.hidesBottomBarWhenPushed = YES;
myClass1.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:myClass1 animated:YES];
[myClass1 release];
何もありません-エラーのない空のtableView...