【发布时间】:2012-04-05 22:14:28
【问题描述】:
我的应用程序中有一个静态表格视图。此表视图用于首选项。
表格视图中的一个部分只有一个包含UISwitch 的单元格。当这个开关被激活时,我想显示下面的部分,如果不是,我想隐藏下面的部分。所有部分(也应该隐藏/显示的部分)都是使用 Interface Builder 设置的。
当表格视图是静态的,因为静态表格视图没有数据源时,有什么方法可以隐藏或显示此部分?如果更容易,我也可以同意使用相同的部分,但在开关打开或关闭时从该部分添加/隐藏行。
编辑
我已经接近了如何做到这一点。
将节中单元格的高度和节的页脚和页眉的高度设置为0,我可以几乎隐藏节。我在上面的部分和下面的部分之间仍然有一些间距,我无法弄清楚如何摆脱。 有谁知道这个额外的间距是从哪里来的?请看下面的照片。
这是我用来几乎隐藏该部分的代码。
/* Will display cell */
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 2)
cell.hidden = YES;
else
cell.hidden = NO;
}
/* Height of cell */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 2)
return 0;
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
/* Height of section header */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 2)
return 0;
return [super tableView:tableView heightForHeaderInSection:section];
}
/* Height of section footer */
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 2)
return 0;
return [super tableView:tableView heightForFooterInSection:section];
}
这就是表格视图现在的样子。还有一些空间我需要隐藏。额外的空格位于标有“Arbejde”和“Anden”的部分之间。
【问题讨论】:
标签: iphone uitableview static datasource