ios - 清除节标题上方的 UITableViewCells

标签 ios objective-c uitableview

我有一个 UITableView,如下图所示:

Before scroll:
|         |
|         |
|         |  < Clear cell, showing view below table
|         |
|---------|
| section |  < Section header
|---------|
|    1    |
|    2    |
|    3    |
|    4    |
|    5    |


After scroll:
|         |
|         |
|    1    |  < Don't want to see these cells above the section
|    2    |
|---------|
| section |  < Section header
|---------|
|    5    |
|    6    |

我在第一部分使用了透明单元格,因为我希望人们甚至可以从屏幕顶部滚动表格。

如何确保节标题上方的单元格不可见?

最佳答案

我已经实现了此方法,使我的表格 View 在向上滚动时停止在单元格 1 处,也许您可​​以根据您的场景进行调整。

int start;
int stop;

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {

    NSArray *paths = [self.tableView indexPathsForVisibleRows];
    @try{
    start = [[paths objectAtIndex:0] row];
    }
    @catch (NSException* NSRangeException) {
        NSLog(@"exception");
    }
}


    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

        NSArray *paths = [self.tableView indexPathsForVisibleRows];
        @try{
          stop = [[paths objectAtIndex:0] row];
        }
        @catch (NSException* NSRangeException) {
            NSLog(@"exception");
        }
        if(stop == 0 && start > 1){
            [UIView animateWithDuration:0.35 animations:^{
                [scrollView setContentOffset:CGPointMake(0, 44)];
            }];
        }

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if(indexPath.row == 0){

                self.tableView.contentOffset = CGPointMake(0, 44);

        }
    ......
    }

关于ios - 清除节标题上方的 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18770097/

相关文章:

ios - 多重分配和零指针分配内存概念

swift - 创建自定义 UITableView 类

ios - 在 Swift 中以编程方式将 UITableViewStyle 更改为 Plain?

ios - 设置空 TableView 空间的背景颜色

ios - 在 iOS 中合并 2 个 pdf 文件

ios - 从字典数组中删除重复项,Swift 3

ios - 如何使用 NSUserDefaults 检查当前时间和上次发布时间?

ios - 如何将十六进制值转换为 NSString?

ios - 设置 View 框架并转换另一个 View - 奇怪的行为

ios - 在 Objective-C 中的方法之间传递信息