Ios 如何在展开tableview后在UITableView的节和行之间留出空间,以及在折叠tableview后删除空间

Ios 如何在展开tableview后在UITableView的节和行之间留出空间,以及在折叠tableview后删除空间,ios,objective-c,uitableview,expandable-table,Ios,Objective C,Uitableview,Expandable Table,我正在设计一个包含多个节和行的uitableview,在该节中我有展开和折叠功能。现在,当行展开时,我在行和节之间留出了空间,如下图所示 这是我展开和折叠节的代码。对于节,我使用页眉视图 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return menuarray.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsIn

我正在设计一个包含多个节和行的uitableview,在该节中我有展开和折叠功能。现在,当行展开时,我在行和节之间留出了空间,如下图所示

这是我展开和折叠节的代码。对于节,我使用页眉视图

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return menuarray.count;
}

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  //return menuarray.count;
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
     NSArray *arr=[menuarray[section] valueForKey:@"menu"];
    return arr.count;
}else{
    return 0;
}
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {

static NSString *CellIdentifier = @"MenudetailsTblCell";

menudetailscell = ( MenudetailsTblCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//    [self.tblview registerNib:[UINib nibWithNibName:@"MenudetailsTblCell" bundle:nil]
//forCellReuseIdentifier:@"MenudetailsTblCell"];
if (menudetailscell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenudetailsTblCell" owner:self options:nil];
    menudetailscell = [nib objectAtIndex:0];

}



if (menudetailscell == nil)
{
    menudetailscell = [[MenudetailsTblCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
     }
menudetailscell.contentView.layer.cornerRadius = 5;
menudetailscell.contentView.layer.masksToBounds = YES;
NSArray *arr=[menuarray[indexPath.section] valueForKey:@"menu"];
menudetailscell.typelbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:@"name"];
 menudetailscell.describtionlbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:@"description"];
NSString *cost=[NSString stringWithFormat:@"%@%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"price"],@".00"];
    NSString *imgid=[NSString stringWithFormat:@"%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"idmenus"]];
NSString *tax=[NSString stringWithFormat:@"%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"tax"]];
if ([tax isEqualToString:@"tax"]) {
  menudetailscell.taxlbl.text=@"(*Inclusive all taxes)";
}else{

menudetailscell.taxlbl.text=@"(*Exclusive all taxes)";
}
menudetailscell.ratelbl.text=[NSString stringWithFormat:@"%@ %@",[[arr objectAtIndex:indexPath.row]valueForKey:@"country"],cost];

NSString *typeimgUrl1 = [NSString stringWithFormat:@"%s/presignin/menu/showMedia?idMenu=%@",urlPath,imgid];
NSURL *imageURL=[NSURL URLWithString:typeimgUrl1];
menudetailscell.imgview.imageURL=imageURL;

menudetailscell.selectionStyle = UITableViewCellSelectionStyleNone;
return menudetailscell;


 }

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 70.0f;
 }

 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{



static NSString *CellIdentifier = @"Menusectioncell";

menusectioncell = ( Menusectioncell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (menusectioncell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Menusectioncell" owner:self options:nil];
    menusectioncell = [nib objectAtIndex:0];

   }



if (menusectioncell == nil)
{
    menusectioncell = [[Menusectioncell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
   }


if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
    menusectioncell.Sectiomtitlebtn.selected = YES;
     menusectioncell.dotlbl.hidden=NO;
}
else{
menusectioncell.dotlbl.hidden=YES;
}
menusectioncell.Sectiomtitlebtn.tag=section;


menusectioncell.dotlbl.layer.cornerRadius = menusectioncell.dotlbl.frame.size.height/2;
menusectioncell.dotlbl.layer.masksToBounds = YES;

[menusectioncell.Sectiomtitlebtn addTarget:self action:@selector(btnTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
NSString *btntitle=[menuarray[section] valueForKey:@"catagory"];
itemarr=[menuarray[section] valueForKey:@"menu"];
NSString *items=[itemarr[0] valueForKey:@"name"];
menusectioncell.sectiontitleilb.text=btntitle;
menusectioncell.itemslbl.text=[NSString stringWithFormat:@"%@.,etc...",items];
menusectioncell.selectionStyle = UITableViewCellSelectionStyleNone;
return menusectioncell.contentView;

 }

  -(IBAction)btnTapShowHideSection:(UIButton*)sender
 {


if (!sender.selected)
{
    if (!isMultipleExpansionAllowed) {
        [arrSelectedSectionIndex replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:sender.tag]];
    }else {
        [arrSelectedSectionIndex addObject:[NSNumber numberWithInteger:sender.tag]];
    }
    menusectioncell.dotlbl.hidden=YES;
    sender.selected = YES;
}
else{
    sender.selected = NO;
    menusectioncell.dotlbl.hidden=NO;
    if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:sender.tag]])
    {
        [arrSelectedSectionIndex removeObject:[NSNumber numberWithInteger:sender.tag]];
    }
}

if (!isMultipleExpansionAllowed) {
    [_tblview reloadData];
}else {
    [_tblview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];

}

}


 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

return 75;

 }

我只是想为headerview和我使用的两个不同单元格的行提供maincourse和down细节之间的空间。请帮我解决这个问题。

然后只需在
heightsforheaderinsection
中返回更多高度即可。例如80而不是70。就这样


您还可以根据页眉高度管理
menuseConctionCell.contentView
的高度

你想在
主菜
蔬菜比里亚尼(第一排)
之间留出更多空间吗?@lion感谢qiuck response是的,我想在主菜和蔬菜比里亚尼(第一排)之间留出更多空间只需返回一个更大的节头高度,返回一个那么高的灰色视图,但是给它一个白色的子视图,插入y=5,高度=sectionHeaderHeight-10对不起,我找不到你,如何显示我给出的灰色视图,你能给出清晰的图片吗?@Ashoklondh他可以根据我的要求修改它。它应该在节展开时出现。如何在右侧和左侧为行留出空间。当我折叠灰色时,我已经展开和折叠节不应该出现。