数据未加载到TableView

时间:2011-04-24 10:30:08

标签: iphone objective-c core-data

我有以下方法1)创建一个会话对象,2)创建一个Exercise对象,添加到Session,同时创建一个Set对象添加到该练习。

但是我的表没有加载任何数据。我的谓词在fetchResultsController的委托方法中可能是错误的。有什么想法吗?

会话(class file)与练习(c lass file)有许多关系,它与Set(class file)有很多关系。 (单击类文件的链接以查看对象实现)

- (void)createSession
{
 session = (Session *)[NSEntityDescription insertNewObjectForEntityForName:@"Session" inManagedObjectContext:managedObjectContext];
session.timeStamp = self.picker.date;
exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
exercise.name = selectedExerciseName;
[session addExercisesObject:exercise];
 if (![managedObjectContext save:&error]) 
}

-(IBAction)createSet
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:managedObjectContext]];
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
Set *set = (Set *)[NSEntityDescription insertNewObjectForEntityForName:@"Set" inManagedObjectContext:managedObjectContext];
set.weight = [NSNumber numberWithFloat:5.5f];
set.reps = [NSNumber numberWithInt:repSelected];
set.timeStamp = self.picker.date;
[self.exercise addSetsObject:set];
if (![managedObjectContext save:&error]) 
}

对于FetchResultsController的委托,我有:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Set" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"sets == %@", exercise.name]];

最后,我在这里参加了练习对象

- (void)addSetsObject:(Set *)value {    
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    [self willChangeValueForKey:@"sets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"sets"] addObject:value];
    [self didChangeValueForKey:@"sets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];


      [changedObjects release];
    }
    - (void)addSets:(NSSet *)value {    
        [self willChangeValueForKey:@"sets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
        [[self primitiveValueForKey:@"sets"] unionSet:value];
        [self didChangeValueForKey:@"sets" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}

0 个答案:

没有答案