目前正在处理核心数据
以下是我的数据模型:
WorkoutType (One to Many workouts with WorkoutSet)
WorkoutSet (One to Many days with WorkoutDay)
WorkoutDay (One to Many exercises with WorkoutExercise
WorkoutExercise
所有4的数据通过4个tableviews显示。
我正在使用FetchedResultsController,一切正常。
我的下一个问题是我从workoutExerciseTableViewController传递到另一个ViewController并漫游我如何将所有数据传递给此视图控制器。例如,我需要访问exerciseType,workoutSet和workoutDay数据,这些数据是为了达到exerciseExercise数据而选择的。
下面是我的WorkoutExerciseTableViewController中的fetchedResultsController:
-(void)fetchWorkoutExercises
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"WorkoutExercise"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"workoutDay = %@", self.workoutDay];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"exerciseName" ascending:YES];
[fetchRequest setSortDescriptors:@[sortDescriptor]];
[fetchRequest setPredicate:predicate];
self.fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil cacheName:nil];
//self.fetchedResultsController.delegate = self;
NSError *error;
if (![self.fetchedResultsController performFetch:&error])
{
NSLog(@"Fetch failed: %@", error);
}
}
感谢您提前提供任何帮助:)
答案 0 :(得分:0)
您只需将选定的WorkoutExercise •exercise
传递给下一个视图控制器,因为可以从那里访问其他数据
WorkoutDay *day = exercise.workoutDay;
WorkoutSet *set = day.workoutSet;
WorkoutType *type = set.workoutType;
使用反向关系。