Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从分组UITableView中删除节后出现间隙_Objective C_Ios_Uitableview - Fatal编程技术网

Objective c 从分组UITableView中删除节后出现间隙

Objective c 从分组UITableView中删除节后出现间隙,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我的表中有3个部分,每个部分最多包含1行 但是,根据变量的不同,中心行可能显示在tableview中,也可能不显示在tableview中。我的代码实现如下所示: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSString *currentUserId = [[UserStockInfo sharedUserStockInfo]getUserId];

我的表中有3个部分,每个部分最多包含1行

但是,根据变量的不同,中心行可能显示在tableview中,也可能不显示在tableview中。我的代码实现如下所示:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *currentUserId = [[UserStockInfo sharedUserStockInfo]getUserId];
    switch (section) {
        case 0: //Follow button
            return 1;
            break;

        case 1://Center cell
            if (self.user.exists) {
                return 1;
            }
            else {
                return 0;
            }
            break;

        case 2://question
            return 1;

        default:
            return 0;
            break;
        }

}
我面临的问题是,对于不应该显示中心单元格的情况,第一部分和第三部分之间仍然会出现间隙(如下所示)。移除中心单元后,如何消除多余的间隙

带中心单元格/部分:

无中心单元格/部分(出现间隙):


您应该设置
UITableView
的页脚和页眉的适当高度

在代理中实现以下方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
例如,对于第二部分,您可以返回0:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     if (section == 1) return 0;
     else return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
     if (section == 1) return 0;
     else return 10;
}

希望,这将帮助您

我认为您应该实现(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView


谢谢你的建议。但是,在我添加上述方法之后,以及在将页脚和页眉高度设置为0之后,没有任何变化。这对我来说非常有效。尝试使用这些函数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.user.exists) {
        return 3;
    }
    return 2;
}