我有一个由fetchedResultsController支持的表视图。在我的表格单元格中,我有一个执行软删除的按钮,就视图而言...点击按钮,执行软删除的选择器被调用,并且...应该发生某事(I'我尝试了很多东西),但没有尝试过像Apple的行动画那样的动画。核心数据/ UITableView上的动画数据刷新(软删除)
我可以执行简单的行动画,就像使其滑动一样(在我告诉表重新加载之后会留下一个空行),这反过来又有点刺耳的效果)。这是我来最接近:
-(void) completeTask: (id) sender { NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; NSDate *date = [[NSDate alloc] init]; NSManagedObject *task = [self.fetchedResultsController objectAtIndexPath:indexPath]; [task setValue:date forKey:@"complete"]; AppController *ac = [AppController sharedAppController]; NSManagedObjectContext *moc = [ac managedObjectContext]; NSError *error = nil; if(![moc save:&error]){ NSLog(@"%@ %@",error, [error description]); exit(-1); } else { UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; CGRect cellFrame = cell.frame; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.35]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(someAnimationDidStop:finished:context:)]; cell.frame = CGRectMake(cellFrame.size.width , cellFrame.origin.y, cellFrame.size.width, cellFrame.size.height); [UIView commitAnimations]; } } -(void) someAnimationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)duration { NSLog(@"Animation Stopped"); [self fetchResults]; // this guy performs a new fetch and table data reload }
我觉得我在正确的轨道上是有点,但我不认为这真的是相当的答案。我希望以某种方式controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
将是答案。我的猜测是,如果我需要股票Apple动画,我将不得不创建一个单独的NSMutableArray来跟踪结果,并确保它保持同步。
思想和观点?
谢谢!
你是对的 - 在对我的委托方法进行一些更改以正确启用真正的删除后,看起来我的答案在下面停止工作,直到我删除了手动表管理。谢谢! – Cameron 2011-05-09 19:38:05