sorting描述符不正确或一致

我在4个实体之间使用sorting描述符和集合谓词。

实体一:workoutType关系训练1到多个实体二:workoutSet关系天1到多个实体三:workoutDay关系练习1到多个实体四:workoutExercise

倒数也被设置。

我收到的问题是sortDescriptor在幕后正常工作,但是显示的内容不正确。

例如在我的workoutDay实体,我有stringtypes的属性dayName。

储存值:第1天,第2天,第3天。

当在tableview中运行显示值时:第1天,第3天,第2天。

当我点击从上到下的日子:

第1天….下一个视图控制器显示正确的第1天的数据。

第3天….下一个视图控制器显示第2天的数据(不是第3天)。

第2天….下一个视图控制器显示第3天的数据(不是第2天)。

所以sorting描述符正在工作,但显示的内容与正在select的内容不相关。

码:

-(void)fetchWorkoutDays { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"WorkoutDay"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"workoutSet = %@", self.workoutSet]; [fetchRequest setPredicate:predicate]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dayName" ascending:YES]; [fetchRequest setSortDescriptors:@[sortDescriptor]]; 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); } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } WorkoutDay *day = [self.workoutSet.days.allObjects objectAtIndex:indexPath.row]; cell.textLabel.text = day.dayName; return cell; } 

感谢您的任何帮助。

如果需要更多的代码,我可以显示它。

workoutSet.days是一个按顺序排列的集合,所以每次configuration一个单元格时,都会按照随机顺序获取这些项目。 您应该要求FRC为indexPath返回适当的对象。