ios - numberOfRowsInSection 重复计算最后一个部分
问题描述
可能重复:表格视图从最后一节开始:numberOfRowsInSection numberOfRowsInSection 从最后一节开始
我的部分代码数量:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
// NSLog(@"outsideindx%d", indexsection);
for (int indexsection = 0 ; indexsection < [arrayOfArrays count ] ; indexsection ++)
{
NSLog(@"outsidesection%d",section);
if([buttonTags containsObject:@(section)])
{
if (section == indexsection)
{
NSLog(@"HIDING!");
return 0;
}
else
{
return [arrayOfArrays [indexsection] count];
}
}
else
if(section == indexsection)
{
//stars with 1 to 0
return [arrayOfArrays [indexsection] count];
}
}
}
我的代码做了什么,它隐藏了我的标题中的按钮。buttonTags 是一个包含被点击按钮的数组。所以我想做的是隐藏被点击的按钮。如果 buttonTag 的值为 button[1],则部分 == 1 将被隐藏。
如果 buttonTags 包含 [ 0 , 1] 则部分 0 和 1 将被隐藏。
但结果破坏了我的代码的想法结果从 1 开始,我点击了按钮 [0]。
结果是这样的:
insidesection: 1
insidesection: 1
insidesection: 0
outsidesection: 1
outsidesection: 0
部分结果与发布的重复项不同,
我的部分数量在这里:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 2;
}
我需要从 0 到 1 开始计数部分。而不是从 1 到 0。
解决方案
当然,您只想查看相关部分,而不是遍历所有部分。就像是:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if([buttonTags containsObject:@(section)]) {
return 0;
} else {
return [arrayOfArrays[section] count];
}
}
推荐阅读
- swift - UICollectionView 在 UICollectionViewCompositionalLayout 上自动滚动
- python - 没有 glfw 上下文无法编译着色器
- css - nth-child(odd) 影响所有孩子而不是奇数
- r - sprintf在R中的函数内部静音
- css - 为什么行类使我的外部 div 适合大小
- php - Wordpress - 如何通过电子邮件向 4000 名订阅者发送通知
- plugins - 如何按规则将 Thunderbird 电子邮件导出到 .eml 文件到文件系统文件夹?
- python - 为什么在属性中执行逻辑而不是在 __init__ 中执行逻辑时会收到 TypeError?
- python - ParserError:为 csv 标记数据时出错
- powerbi - Power Query List.Generate 性能