UITabelView 很好的tabelView文章
tableview的初始化:
static NSString * const prodectMessageCellIdentifier = @"prodectMessageCellIdentifier";
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
_tableView.backgroundColor = [UIColor colorWithRed:234 green:234 blue:234 alpha:1];
_tableView.separatorStyle = NO;
[_tableView registerClass:[ProductMessageTableViewCell class] forCellReuseIdentifier:prodectMessageCellIdentifier];
}
return _tableView;
}
复制代码
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ProductMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:prodectMessageCellIdentifier forIndexPath:indexPath];
if (indexPath.section == 0) {
[cell showNumLabel];
}
else{
[cell showSelectButton];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.picImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"cp_%ld",indexPath.row]];
cell.nameLabel.text = @"古藤红葡萄酒";
cell.adressLabel.text = @"米莱庄园 Milazzo";
cell.codeLabel.text = [NSString stringWithFormat:@"产品编码 : 3709010GAC03"];
cell.numLabel.text = @"0";
cell.totleNumLabel.text = @"10";
return cell;
}
复制代码
//设置头部视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView * view = [[UIView alloc]init];
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(PxtoPoint_Width(50), PxtoPoint_Width(60), PxtoPoint_Width(230), PxtoPoint_Width(65))];
if (section==0) {
lab.text = @"包装码";
}
if (section == 1) {
lab.text = @"商品码";
}
[view addSubview:lab];
UIImageView * ImageView = [[UIImageView alloc]initWithFrame:CGRectMake(PxtoPoint_Width(1100), PxtoPoint_Width(60), PxtoPoint_Width(100), PxtoPoint_Width(65))];
ImageView.image = [UIImage imageNamed:@"icon_sm"];
[view addSubview:ImageView];
return view;
}
复制代码
//让TableViewSection在Plan的模式下不悬浮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = PxtoPoint_Width(160);
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=-50) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
复制代码