UITableViewWithUICollectionView(跟美团,饿了吗点菜页面一样)

来源:互联网 发布:js仿京东选择商品规格 编辑:程序博客网 时间:2024/04/30 23:49


UITableView ,通过UITableView实现两行数据进行联动,请先看上面图片(具体请看demo)

UICollectionView ,通过实现UITableVie头部Header效果进行联动,请先看上面图片(具体请看demo)



1:首先先建立左边_leftTableView 和右边的_rightTableView
2:实现数据填充
3:重要的方法(

[_leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];

4.进行关联(一般我们用这个实现购物功能)

5.贴出一部分代码进行展示

// TableView分区标题即将展示

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {

    

    //当前的tableViewRightTableViewRightTableView滚动的方向向上,RightTableView是用户拖拽而产生滚动的((主要判断RightTableView用户拖拽而滚动的,还是点击LeftTableView而滚动的)

    if ((_rightTableView == tableView) && !_isScrollDown && _rightTableView.dragging) {

        [self selectRowAtIndexPath:section];

    }

}


// TableView分区标题展示结束

- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section {

    

    //当前的tableViewRightTableViewRightTableView滚动的方向向下,RightTableView是用户拖拽而产生滚动的((主要判断RightTableView用户拖拽而滚动的,还是点击LeftTableView而滚动的)

    if ((_rightTableView == tableView) && _isScrollDown && _rightTableView.dragging)

    {

        [self selectRowAtIndexPath:section + 1];

    }

    

}

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

    

    if (_leftTableView != tableView) return;

    

    _selectIndex = indexPath.row;

    [_rightTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:_selectIndex] atScrollPosition:UITableViewScrollPositionTop animated:YES];

}



//当拖动右边TableView的时候,处理左边TableView

- (void)selectRowAtIndexPath:(NSInteger)index {

    

    [_leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];

}

//标记一下RightTableView的滚动方向,是向上还是向下

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

    

    static CGFloat lastOffsetY = 0;

    UITableView *tableView = (UITableView *)scrollView;

    if (_rightTableView == tableView) {

        _isScrollDown = lastOffsetY < scrollView.contentOffset.y;

        lastOffsetY = scrollView.contentOffset.y;

    }

   } 







具体的请到我的github上下载查看,里面有详细的讲解,我的github地址:https://github.com/986138497/UITableViewWithUICollectionView








0 0
原创粉丝点击