第一個問題:UITableViewStyleGrouped 底部20間距 沒找到原因只能設置contentInset了
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
_tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, CGFLOAT_MIN)];
_tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, CGFLOAT_MIN)];
[self.view addSubview:_tableView];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor greenColor];
// _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
// _tableView.contentInset = UIEdgeInsetsMake(0, 0, -20, 0);
self.automaticallyAdjustsScrollViewInsets = NO;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 25;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return CGFLOAT_MIN;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.backgroundColor = [UIColor redColor];
}
cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
第二個問題 masonry groupstyle設置表頭時會出現(xiàn)大概30左右間距
先添加到tableview上 在layoutifneed獲取到表頭的具體frame 在設置表頭
原理是直接設置frame沒類似問題
當tableviewHeader是用frame有確定的寬高時 間距是不存在的
_tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
[self.view addSubview:_tableView];
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
UIView *tabHeader = [UIView new];
tabHeader.frame = CGRectMake(0, 0, 320, 100);
tabHeader.backgroundColor = [UIColor greenColor];
_tableView.tableHeaderView = tabHeader;
_tableView.delegate = _adapterManager;
_tableView.dataSource = _adapterManager;
--------基于此作如下處理:
UIView *tabHeader = [UIView new];
tabHeader.backgroundColor = [UIColor greenColor];
[_tableView addSubview:tabHeader];
[self.view layoutIfNeeded];
[tabHeader mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.width.mas_equalTo(_tableView);
make.height.mas_equalTo(_cubeHeadView.frame.size.height);
}];
[self.view layoutIfNeeded];
_tableView.tableHeaderView = tabHeader;
tabHeader是按照cubeHeadView的高度來的
目的是在設置 ( _tableView.tableHeaderView = tabHeader;)之前
獲取tabHeader確定的寬高位置
第三個問題 masonry下 tableview內(nèi)部在嵌套tableview時 被嵌套的contentsize不準確可能和默認高度(44)有關系
第四個問題 tableview UITableViewStyleGrouped時頂部可能出現(xiàn)35間距 如不需tableHeaderView 可做如下處理:
_tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, QNJWIDTHSCREEN, CGFLOAT_MIN)];
不可改為CGRectZero