#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

网友评论