I am designing a uitableview with multiple sections and row in that section i have expand and collapse functionality for that.Now when the row is expanded I have give space between row and section like below image.enter image description here

here is my code for expand and collapsing the the section.and for section i use header view.

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

 }

I just wanted to give space between maincourse and down details for headerview and rows I am using 2 different cell. Please help me out to solve this.

1

There are 1 best solutions below

2
On

then just return more height in heightForHeaderInSection. For example 80 instead of 70. that's it!

And you could manage height of menusectioncell.contentView also according to header height!