如何从Storyboard中创建的静态UITableView中删除单元格 [英] How to remove cell from static UITableView created in Storyboard

查看:85
本文介绍了如何从Storyboard中创建的静态UITableView中删除单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但我遇到了麻烦。



我有一个静态UITableView,我想要以编程方式删除它,如果不需要的话。



我有一个IBOutlet

  IBOutlet UITableViewCell * cell15; 

我可以通过调用



<$来删除它p $ p> cell15.hidden = true;

这隐藏了它,但留下了一个空白区域,我曾经无法获得摆脱它。



也许黑客会将它的高度改为0?

   - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:indexPath 
{
//我会放在这里?
}

非常感谢!

解决方案

您无法在数据源中真正处理这个问题,因为对于静态表,您甚至不实现数据源方法。高度是要走的路。



试试这个:

   - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell == cell15&& cell15ShouldBeHidden)// BOOL说单元格应隐藏
返回0.0;
else
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}

更新



看来,在autolayout下,这可能不是最好的解决方案。有一个替代答案这里可能有所帮助。


This should be easy, but I'm having trouble.

I have a static UITableView with a cell that I would like to remove programmatically if it's not needed.

I have a IBOutlet for it

IBOutlet UITableViewCell * cell15;

And I can remove it by calling

cell15.hidden = true;

This hides it, but leaves a blank space where the cell used to be and I can't get rid of it.

Perhaps a hack would be to change the height of it to 0?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:indexPath
{
//what would I put here?
}

Thanks so much!

解决方案

You can't really deal with this in the datasource since with static tables you don't even implement the datasource methods. The height is the way to go.

Try this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == cell15 && cell15ShouldBeHidden) //BOOL saying cell should be hidden
        return 0.0;
    else
        return [super tableView:tableView heightForRowAtIndexPath:indexPath]; 
} 

Update

It appears that, under autolayout, this may not be the best solution. There is an alternative answer here which may help.

这篇关于如何从Storyboard中创建的静态UITableView中删除单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆