iphone - 只有在 Insert-Animation 完成后才重新加载 UITableViewCell

标签 iphone ios objective-c uitableview uikit

所以我要将 UITableViewCell 插入到我的 tableView 中。

[searchTableView beginUpdates];
[searchTableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationTop];
[searchTableView endUpdates];

在此之后,我运行一个异步请求,该请求使用淡入淡出动画更新 tableviewcell。

[someRequestWithCompletion:^(id data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [searchTableView beginUpdates];
            [searchTableView reloadRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            [searchTableView endUpdates];
        });
 }];

但是这个请求有可能在插入动画完成之前完成。如果请求在插入动画之后完成,则没有问题,如果它之前完成并在当前插入的同一单元格上调用 reloadRowsAtIndexPaths,则该单元格立即显示并在插入时强制重新加载-动画淡出。

有没有办法在cell完全插入后触发reload更新?最好的方法是什么?

如果有任何问题,请在评论中告诉我

最佳答案

试试这个..

您可以在动画完成后重新加载您的 TableView。

[CATransaction begin];
[searchTableView beginUpdates];

[CATransaction setCompletionBlock: ^{
        [searchTableView reloadData];
    }];

[searchTableView deleteRowsAtIndexPaths: [NSArray arrayWithObjects: indexPath, nil]
                       withRowAnimation: UITableViewRowAnimationAutomatic];

[searchTableView endUpdates];

[CATransaction commit];

关于iphone - 只有在 Insert-Animation 完成后才重新加载 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15325092/

相关文章:

iPhone:调用textViewDidChange安全吗?

objective-c - 使用 Objective-C 的 JSON 框架解析嵌套的 JSON 对象

ios - 带有 GPUImageBuffer 目标的 GPUImagePicture?

objective-c - 在 View 上显示图像 1 秒

ios - Apple 是否允许我们将用户的信用卡信息从应用程序发送到服务器以进行支付?

ios - 如何检测之前是否显示过位置服务弹出窗口

ios - UISegmentedControl 自定义在 ios 7 中不起作用

iphone - 如何更改应用从后台重新激活时显示的 iOS View 。

iphone - 在 iPhone 中,是否保证始终调用 viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear?

ios - 如何为 UILabel 制作马车