【发布时间】:2011-08-19 20:12:58
【问题描述】:
我有一个由 fetchedResultsController 支持的表视图。在我的表格单元格上,我有一个执行软删除的按钮,就视图而言......点击按钮,执行软删除的选择器被调用,并且......应该发生一些事情(我'我尝试了很多东西),但我没有尝试过像 Apple 的行动画这样的动画。
我可以执行简单的行动画,比如让它滑开(这会留下一个空白行,直到我告诉表格重新加载,这反过来又有点不和谐)。这是我最近的一次:
-(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, [错误描述]);
退出(-1);
} 别的 {
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 提交动画];
}
}
-(void) someAnimationDidStop:(NSString *)animationID
完成:(布尔)完成上下文:(无效*)持续时间{
NSLog(@"动画停止");
[自取结果]; // 这家伙执行新的 fetch 和表数据重新加载
}
我觉得我走在了正确的轨道上,但我认为这并不是真正的答案。我希望以某种方式controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: 会是答案。我的猜测是,如果我想要 Apple 动画,我将不得不创建一个单独的 NSMutableArray 来跟踪结果并确保它保持同步。
想法和意见?
谢谢!!!
【问题讨论】:
标签: ios uitableview core-data animation