title: in tableview how dynamically changing section y position ios
body: <p><img src="https://i.stack.imgur.com/IyA8U.png" alt="">    <img src="https://i.stack.imgur.com/VjxpL.png" alt=""></p>
  
  <p>The Screen Shot I added here i have dynamic data in my sections. Each section have one row and have label and values in it . my problem is when i add or change count of values its sections 'y' margin changes. please help me if anyone Know</p>
  
  <p>here is my code</p>
  
  <pre><code>- (UIView *)tableView:(UITableView *)tableView1 viewForHeaderInSection:(NSInteger)section{
  
      UIView *section1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView1.bounds.size.width, tableView1.bounds.size.height)] ;
      [section1 setBackgroundColor:[UIColor clearColor]];
  
  
      return section1;
  
  }
  
  -(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
  {
  
      if(section !=0){
          return 22;
      }
      return 0.0;
  }
  -(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
  {
  
  
      return 0.0;
  }
  
  //dynamic decide no of sections in table
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  
      if(tagLastbutton == lastRow){
  
          lastRow = lastRow +1;
          return lastRow;
  
      }
      return lastRow;
  
      //[self.arrayObjects count];
  }
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
  
      return 1;
  }
  
  
  
  //  Return YES to allow the user to reorder table view rows
  //
  - (BOOL)tableView:(UITableView *)tableView
  canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  {
      return NO;
  }
  
  
  // Return a cell containing the text to display at the provided row index.
  //changing background according to input
  - (UITableViewCell *)tableView:(UITableView *)tableView
           cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
      static NSString *CellIdentifier = @"MyuSocialNetworkCell";
      CreateNewProfileViewCell * cell = (CreateNewProfileViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  
      if (cell == nil)
      {
  
  
          NSArray *nibObjects= [[NSBundle mainBundle] loadNibNamed:@"CreateNewProfileViewCell" owner:nil options:nil];
  
          for(id currentObject in nibObjects)
          {
              if([currentObject isKindOfClass:[CreateNewProfileViewCell class]])
              {
                  cell = (CreateNewProfileViewCell *) currentObject;
                  break;
  
              }
          }
  
      }
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
      //[indexPath.row color]
     // if([self.subCategoryString length] != 0){
         // cell.addFoodAllergyLabel.text = self.subCategoryString;
     // }
      NSString *str;
      if(indexPath.section &lt; [self.namesFoodSubCategoryLabels count]){
        str = [self.namesFoodSubCategoryLabels objectAtIndex:indexPath.section];
      }
      int len=str.length;
  
      NSLog(@"Ch ###########################%u",len);
      len=floor(len/29);
      NSLog(@"Ch ##After Row##################%u",len);
      len++;
     // len++;
      /*
      CGRect frameCell = CGRectMake(cell.frame.origin.x, cell.frame.origin.y+newCellPosition, cell.frame.size.width, cell.frame.size.height);
      cell.frame = frameCell;
      */
  
      CGRect frame = CGRectMake(cell.addFoodAllergyLabel.frame.origin.x, cell.addFoodAllergyLabel.frame.origin.y, cell.addFoodAllergyLabel.frame.size.width, cell.addFoodAllergyLabel.frame.size.height*len);
      cell.addFoodAllergyLabel.numberOfLines = len;
      cell.addFoodAllergyLabel.frame = frame;
  
      CGRect frameMidBox = CGRectMake(cell.midMainRowBoxImageView.frame.origin.x, cell.midMainRowBoxImageView.frame.origin.y, cell.midMainRowBoxImageView.frame.size.width, cell.midMainRowBoxImageView.frame.size.height*len);
  
      cell.midMainRowBoxImageView.frame = frameMidBox;
  
      CGRect frameLowerCornerBox = CGRectMake(cell.lowerRowCornerImageView.frame.origin.x, cell.lowerRowCornerImageView.frame.origin.y+((len*26)-26), cell.lowerRowCornerImageView.frame.size.width, cell.lowerRowCornerImageView.frame.size.height);
  
      newCellPosition = cell.lowerRowCornerImageView.frame.origin.y+22;
  
      cell.lowerRowCornerImageView.frame = frameLowerCornerBox;
      CGRect frameButtonImage = CGRectMake(cell.addFoodAllergyButton.frame.origin.x, cell.addFoodAllergyButton.frame.origin.y+((len * 13)-13), cell.addFoodAllergyButton.frame.size.width, cell.addFoodAllergyButton.frame.size.height);
  
      cell.addFoodAllergyButton.frame = frameButtonImage;
      cell.addFoodCategoryImageView.frame = frameButtonImage;
      NSLog(@"Array&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;%@",self.namesFoodSubCategoryLabels);
      NSLog(@"indexPath.row %u",indexPath.row);
  
      if(indexPath.section &lt; [self.namesFoodSubCategoryLabels count]){
          cell.addFoodAllergyLabel.text = [self.namesFoodSubCategoryLabels objectAtIndex:indexPath.section];
          cell.addFoodCategoryImageView.image = [UIImage imageNamed:[self.imagesFoodCategories objectAtIndex:indexPath.section]];
  
  
  
      }
      //CGRect frame = CGRectMake(0, 0, 60, 60);
      //cell.frame=frame;
  
      cell.addFoodAllergyButton.tag = indexPath.section+1;
      cell.addFoodAllergyLabel.tag  = indexPath.section+1;
      [cell.addFoodAllergyButton addTarget:self action:@selector(addFoodAllergyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
  
      return cell;
  }
  
  -(CGFloat) tableView:(UITableView *) tableView1 heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  
      for(int i=0 ; i&lt; [self.namesFoodSubCategoryLabels count] ; i++){
  
  
          NSString *str = [self.namesFoodSubCategoryLabels objectAtIndex:i];
          int len=str.length;
  
          NSLog(@"Ch ######heightForRow#####################%u",len);
          len=floor(len/29);
          len++;
          //len++;
          NSLog(@"Ch ##After heightForRow###################%u",len);
          return ((len*26)+11);
  
  
      }
  
      return 37;
  }
  </code></pre>
  
  <p>I am changing dynamically background,label and section height but not able to handle sections y dynamically. so as screenshots shows that my problem is to manage sections margin in y position which is change between every two sections.</p>