如何隐藏一个静态的UITableViewCell?

你如何隐藏一个静态单元格?

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

我试过了:

imageCell.hidden = YES; //did not work 

我已经看到了答案,build议改变数据源或使用:

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

但我无法find一个方法来做一个特定的视图单元格。

我想实现的是:

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

现在这里是捕获,图像被asynchronous下载,因此可能会在尝试downlaod之前调用deleguate方法。

请执行下列操作 :

 - (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; } 

而且你可以使用下面的命令来animation(例如每次载入图像时):

 [myTable beginUpdate]; [myTable endUpdate]; 

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

如果你想从字面上隐藏图像不存在的单元格,你可以试试这个:

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; return [cell imageView] ? 44.0f : 0.0f; }