上下两个TableView滚动,TableView横向滚动

#import "ViewController.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

//屏幕高度

#define ScreenHeight    [UIScreen mainScreen].bounds.size.height

//屏幕宽度

#define ScreenWidth      [UIScreen mainScreen].bounds.size.width

@property (nonatomic, strong) UITableView *topTableView; //!< 上方tableViewt

@property (nonatomic, strong) UIView *footView;

@property (nonatomic, strong) UITableView *bottomTableView; //!< 下方tableViewt,可横向滚动

@property (nonatomic, assign) NSInteger rowCount; //!< 行数

@end

@implementation ViewController

- (void)viewDidLoad {

    [superviewDidLoad];

    self.rowCount =30;


    self.topTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];

    [self.view addSubview:self.topTableView];

    self.topTableView.delegate =self;

    self.topTableView.dataSource =self;

    self.topTableView.tableFooterView =self.footView;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return1;

}

- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section {

    if(tableView ==self.bottomTableView) {

        returnself.rowCount;

    }

    return20;

}

- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if(tableView ==self.topTableView) {

        UITableViewCell *cell = [UITableViewCell new];

        cell.textLabel.text = [NSString stringWithFormat:@"topTableView_%@",@(indexPath.row)];

        returncell;

    }


    UITableViewCell *cell = [UITableViewCell new];

    cell.textLabel.text = [NSString stringWithFormat:@"bottomTableView_可横向滚动%@",@(indexPath.row)];

    returncell;

}

- (UIView *)footView{

    if(!_footView) {

         CGFloat viewHeight =self.rowCount *44+self.rowCount;//+ self.rowCount: 分隔线高度 1*rowCount

         _footView = [[UIView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, viewHeight)];


         UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, viewHeight)];

         scrollView.contentSize = CGSizeMake(ScreenWidth*1.5, viewHeight);

         [_footView addSubview:scrollView];


         self.bottomTableView.frame = CGRectMake(0,0, scrollView.contentSize.width, viewHeight);

         [scrollView addSubview:self.bottomTableView];

    }

    return_footView;

}

- (UITableView *)bottomTableView{

    if(!_bottomTableView) {

        _bottomTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];

        _bottomTableView.delegate =self;

        _bottomTableView.dataSource =self;

        _bottomTableView.scrollEnabled =NO;

        _bottomTableView.autoresizesSubviews =NO;

    }

    return_bottomTableView;

}

@end



©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容