gpt4 book ai didi

ios - 在 iOS 中单击 UIButton 时更新 UITableView sectionHeaderHeight

转载 作者:行者123 更新时间:2023-11-29 12:31:46 26 4
gpt4 key购买 nike

美好的一天!我的默认 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com