美文网首页
左右表格的联动

左右表格的联动

作者: 26aa4a305186 | 来源:发表于2018-12-06 16:40 被阅读0次

//MARK: - 一个方法就能搞定 右边滑动时跟左边的联动

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

    // 如果是 左侧的 tableView 直接return

    if(scrollView ==self.leftTableView)return;

    // 取出显示在 视图 且最靠上 的 cell 的 indexPath

    NSIndexPath*topHeaderViewIndexpath = [[self.rightTableViewindexPathsForVisibleRows]firstObject];

    // 左侧 talbelView 移动的 indexPath

    NSIndexPath*moveToIndexpath = [NSIndexPathindexPathForRow:topHeaderViewIndexpath.sectioninSection:0];

    // 移动 左侧 tableView 到 指定 indexPath 居中显示

    [self.leftTableView selectRowAtIndexPath:moveToIndexpath animated:YES scrollPosition:UITableViewScrollPositionMiddle];

}

//MARK: - 点击 cell 的代理方法

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

    // 选中 左侧 的 tableView

    if(tableView ==self.leftTableView) {

        NSIndexPath*moveToIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.row];

        // 将右侧 tableView 移动到指定位置

        [self.rightTableView selectRowAtIndexPath:moveToIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];

        // 取消选中效果

        [self.rightTableViewdeselectRowAtIndexPath:moveToIndexPathanimated:YES];

    }

}

#pragma mark - 懒加载 tableView -

// MARK: - 左边的 tableView

- (UITableView*)leftTableView {

    if (!_leftTableView) {

        UITableView*tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,leftTableWidth,ScreenHeight)];

        [self.viewaddSubview:tableView];

        _leftTableView= tableView;

        tableView.dataSource=self;

        tableView.delegate=self;

        [tableViewregisterClass:[UITableViewCell class] forCellReuseIdentifier:leftCellIdentifier];

        tableView.backgroundColor= [UIColorredColor];

        tableView.tableFooterView= [[UIViewalloc]init];

    }

    return _leftTableView;

}

// MARK: - 右边的 tableView

- (UITableView*)rightTableView {

    if (!_rightTableView) {

        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(leftTableWidth, 0, rightTableWidth, ScreenHeight)];

        [self.viewaddSubview:tableView];

        _rightTableView= tableView;

        tableView.dataSource=self;

        tableView.delegate=self;

        [tableViewregisterClass:[UITableViewCell class] forCellReuseIdentifier:rightCellIdentifier];

        tableView.backgroundColor= [UIColorcyanColor];

        tableView.tableFooterView= [[UIViewalloc]init];

    }

    return _rightTableView;

}

相关文章

  • 左右表格的联动

    //MARK: - 一个方法就能搞定 右边滑动时跟左边的联动 - (void)scrollViewDidScrol...

  • fsLayui联动表格使用(一)

    简单联动表格使用 点击主表格,加载副表格数据,演示地址:http://fslayui.itcto.cn 联动表格配...

  • JimuReport积木报表—表格联动图表专题

    联动是指在一个报表中点击表格某行或者图表某区域,根据点击数据重新渲染联动的图表。积木报表联动分为表格联动图表和图表...

  • Echarts表格联动

    Echarts表格联动设置最主要要设置connect,并且联动表格数据长度要相同。 html js 效果图

  • 实现多方向拖拽EXCEL表格中遇到的问题

    之前在写一个类似于Excel表格页面时,一种方式是可以实现可以上下左右及斜角联动,另一种方式只可以上下左右联动。之...

  • fsLayui联动表格使用(二)

    复杂联动表格使用 点击主表格,加载副表格数据,支持主、副表格的 增删改查 操作。演示地址:http://fslay...

  • tableView左右联动

    实现 tableView联动 主要有两个细节(需要创建两个tableView) 1、点击左侧 cell 让右侧 t...

  • antd tree + 可编辑的表格

    业务场景:    树和表格联动,当选中树的某个节点时,动态添加表格展示. 难点:    1. 树的层级不固定,当我...

  • 两个联动的TableView

    有的软件有联动效果,两个tableview左右可以联动,上下也可以联动,这是怎么做到的呐。先看效果图 代码结构 头...

  • Android开发仿美团购物左右联动列表

    概述 左右联动列表是仿照美团外卖点餐时,左右列表可以联动。比如右边列表会有小项对应左边的,滑动时会置顶,滑动到下一...

网友评论

      本文标题:左右表格的联动

      本文链接:https://www.haomeiwen.com/subject/ngbocqtx.html