美好的一天!我的默认tableview sectionHeaderHeight是56。我想在调用 sectionOpened 方法时更新它。这是以下代码:

- (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 。代码有什么问题?

最佳答案

尝试这样更改高度:

[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;
}

希望它对您有用。

关于ios - 在iOS中单击UIButton时更新UITableView sectionHeaderHeight,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27499018/

10-10 20:37