本文介绍了如何隐藏静态 UITableViewCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏静态单元格?

如果图像不存在,我想隐藏和静态单元格.

I would like to hide and static cell if an image does not exist.

我试过了:

imageCell.hidden = YES; //did not work

我看到了建议更改数据源或使用的答案:

I have seen answers suggesting to change datasource or use:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 0;// will hide all cell
}

但我找不到使用特定视图单元格执行此操作的方法.

But I couldnt find a way to do this with a specific view cell.

我想要达到的目标:

if(image==nil){
//hide imageCell 
}

现在这里是 catch ,图像是异步下载的,因此在尝试下载之前可能会调用委托方法.


Now here is the catch , the image is downloaded asynchronously, so deleguate methods might be called before the attempted downlaod.

推荐答案

执行以下操作:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 2 && !myImageIsLoaded)
        return 0; // Will hide just the third row of your table if myImageIsLoaded is false
    return 44;
}

并且您可以随时使用以下内容为所有动画制作动画(例如,每次加载图像时):

And you can use the following to animate all whenever you want (e.g. each time an image as loaded) :

[myTable beginUpdate];
[myTable endUpdate];

如果您的单元格是静态的,那么它应该可以工作.否则你可能会遇到一些问题.

If your cells are static so it should work. Otherwise you could encounter some problems.

这篇关于如何隐藏静态 UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:50