UITabelView

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);
    }
}
复制代码

转载于:https://juejin.im/post/5a31006f6fb9a0450407e056

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值