ios - 使用 Core Data 将行添加动画到 UITableViewController

标签 ios cocoa-touch ipad core-data uitableview

我正在开发一个使用“主细节”设计模式的 Core Data iPad 应用程序。我正在尝试在更新 ManagedObjectContext 后添加一行动画。目前,当我添加对象时,它只会出现在 TableView 中。我正在使用斯坦福核心数据 TableView 类。

这是我的添加对象委托(delegate)的保存方法:

 - (void)addObjectSaveButtonTapped:(iPadAddObjectViewController *)controller {

    [self dismissModalViewControllerAnimated:YES];
    [self setupFetchedResultsController];
}

这是我的setupFetchedResultsController方法:

    - (void)setupFetchedResultsController {


        NSString *entityName = @"Object";

        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];

        request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"objectName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];

        self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];


        [self performFetch];

    }

这是performFetch方法。

- (void)performFetch
{
    _debug = YES;

    if (self.fetchedResultsController) {
        if (self.fetchedResultsController.fetchRequest.predicate) {
            if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
        } else {
            if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
        }
        NSError *error;
        [self.fetchedResultsController performFetch:&error];
        if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
    } else {
        if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
    }
    [self.tableView reloadData];
}

有什么方法可以为对象添加添加动画吗?

最佳答案

[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:yourIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

UITableView也有类似的方法,insertSections:withRowAnimation:

关于ios - 使用 Core Data 将行添加动画到 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12030558/

相关文章:

ios-charts BalloonMarker.swift 由于信号 : Segmentation fault: 11,命令失败

ios - 如何弱链接 iOS 应用程序委托(delegate)方法?

ipad - PDF Quartz 渲染质量

ios - jw player vast tag 无法在 ipad 中播放(视频内容工作正常)

ios - UITextView 委托(delegate)多次调用

ios - iPhone应用程序因iCloud数据存储准则而被拒绝

iphone - 声音在 iPhone 模拟器中不起作用?

ios - 如何让按钮从下午 3 点到晚上 9 点打开?

objective-c - 图像的像素数据

iphone - 如何在我的应用程序中列出来自 iPhone 钥匙串(keychain)的证书?