UITableViewDelegate 中是否有类似 tableViewWillEndDisplayingCell in iOS 的方法?

Is there any method like tableViewWillEndDisplayingCell in iOS for UITableViewDelegate?

我想在 iPhone 应用程序的 table 视图中淡出单元格,然后再消失。快出现的时候我用

- (void) tableView: (UITableView *) tableView
   willDisplayCell: (UITableViewCell *) cell
 forRowAtIndexPath: (NSIndexPath *) indexPath

使用 0.3 秒的动画将 alpha 从零更改为 1。

我也想在即将消失的时候从1到0。是否有与上述方法类似的方法,或者我还能怎么做?

我不想使用标准 iOS UITableViewRowAnimationFade 因为我不想在重新加载时使用任何其他转换 table.

编辑: 我正在重新加载 table 视图的内容。假设我有一个按钮,我单击它并在我的 table 中重新加载数据。那就是我想要淡出现有单元格并淡入新单元格的时候。

我使用的控制器是一个基本的 UIViewController 实现 UITableViewDataSource UITableViewDelegate UIScrollViewDelegate 协议。

你试过这个吗?

- (void)tableView:(UITableView *)tableView
didEndDisplayingCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath

我想这就是你想要的。

这有点乱七八糟,但应该可行:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    //loop through visible indexPaths
    for (NSIndexPath *indexPath in [self.tableView indexPathsForVisibleRows]) {
        //get each cell
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        //get its location
        CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:indexPath];
        //set its alpha based on whether or not its going off the screen at the top.
        cell.alpha = 1 + rectInTableView.origin.y / rectInTableView.size.height;
    }

}

我找到了解决办法。

就在调用 [self.tableView reloadData] 之前,我正在设置所有可见单元格的动画以淡出。我得到所有可见的单元格并通过

遍历它们
for (NSIndexPath *indexPath in [self.tableView indexPathsForVisibleRows])
{
    // here I animate cells to fade out
}

(感谢@AlexKoren 向我展示了迭代可见单元格的方法)。

因为我使用的是 [self.tableView reloadData] 而没有任何额外的 iOS 内置动画,所以单元格正在消失。所以现在它们首先淡出,然后我的新单元格随着

中定义的动画淡入
- (void) tableView: (UITableView *) tableView
   willDisplayCell: (UITableViewCell *) cell
 forRowAtIndexPath: (NSIndexPath *) indexPath

重要提示:我正在重新加载 table 动画完成后的视图。如果我在遍历单元格后立即调用 [self.tableView reloadData],它会在显示动画之前重新加载 table。因为我知道完成动画需要多长时间我用

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
                {
                    [self.tableView reloadData];
                });

加上之前计算的delay