2014-12-16 1 views
1

Добрый день! Мой TableView по умолчанию sectionHeaderHeight это 56. Я хочу, чтобы обновить его, когда sectionOpened метод получает called.This является следующий код:обновление UITableView sectionHeaderHeight во время UIButton нажмите в iOS

- (void) sectionOpened : (NSInteger) section 
    { 
      sectionHeight = @"YES";  
      getsection = section;  
      NSLog(@"Section Clicked: %ld",(long)getsection); 

      SectionInfo *array = [self.sectionInfoArray objectAtIndex:section]; 
      array.open = YES; 
      NSInteger count = [array.category.menulist count]; 
      NSMutableArray *indexPathToInsert = [[NSMutableArray alloc] init]; 
      for (NSInteger i = 0; i<count;i++) 
      {    
       [indexPathToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]]; 
      } 

      NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init]; 
      NSInteger previousOpenIndex = self.openSectionIndex; 

      if (previousOpenIndex != NSNotFound) 
      { 

       SectionInfo *sectionArray = [self.sectionInfoArray objectAtIndex:previousOpenIndex]; 
       sectionArray.open = NO; 
       NSInteger counts = [sectionArray.category.menulist count]; 
       [sectionArray.sectionView toggleButtonPressed:FALSE]; 
       for (NSInteger i = 0; i<counts; i++) 
       { 
        [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenIndex]]; 
       } 
      } 

      UITableViewRowAnimation insertAnimation; 
      UITableViewRowAnimation deleteAnimation; 
      if (previousOpenIndex == NSNotFound || section < previousOpenIndex) 
      { 

       insertAnimation = UITableViewRowAnimationTop; 
       deleteAnimation = UITableViewRowAnimationBottom; 
      } 
      else 
      { 
       insertAnimation = UITableViewRowAnimationBottom; 
       deleteAnimation = UITableViewRowAnimationTop; 
      } 

      [menulistTable beginUpdates]; 
      if(section==3 || section==4 || section==5) // this section has cells like submenu of a menu 
      { 
       menulistTable.sectionHeaderHeight = 20.0; 
       [menulistTable reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone]; 
       //[menulistTable reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; 
      } 
      [menulistTable insertRowsAtIndexPaths:indexPathToInsert withRowAnimation:insertAnimation]; 
      [menulistTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation]; 
      [menulistTable endUpdates]; 
      self.openSectionIndex = section; 
     } 

Но ничего не происходит. Я также использовал indexSetWithIndex: 0. Что не так в коде?

ответ

1

Попробуйте, как это изменить Рост:

[menulistTable beginUpdates]; 
menulistTable.sectionHeaderHeight = 20.0; 
[menulistTable endUpdates]; 

Отредактировано:

Возьмите переменную установить SectionHeaderHeight. Затем поместите этот код:

[menulistTable beginUpdates]; 
secHeaderHeight = 20.0; 
[menulistTable endUpdates]; 

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

Надеюсь, он сработает для вас.

+0

уже использовал его, но не работал !!! – Poles

+0

@ Поля, пожалуйста, проверьте отредактированный ответ. – cyberlobe

+0

Это также помогает мне: http://stackoverflow.com/questions/27499018/update-uitableview-sectionheaderheight-at-time-of-uibutton-click-in-ios/27499400 – Poles

Смежные вопросы