美文网首页
UITableView 使用

UITableView 使用

作者: 啵啵_long_港 | 来源:发表于2018-11-07 13:53 被阅读2次

    UITableView 取消点击cell的选中颜色

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    UITableView 去掉cell分割线

    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    

    UITableView 设置默认背景颜色灰色为白色

    _tableView.backgroundColor = [UIColor whiteColor];
    

    UITableView 设置xib自定义cell
    注意:MyTableViewCell为xib文件名(loadNibNamed:@"MyTableViewCell")

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"];
        if(nil == cell) {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
        return cell;
    }
    

    UITableView去掉header

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 0.0;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
        if (header == nil) {
            header = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 5, screenWidth, 1)];
            view.backgroundColor = [UIColor whiteColor];
            [header addSubview:view];
        }
        return header;
    }
    

    相关文章

      网友评论

          本文标题:UITableView 使用

          本文链接:https://www.haomeiwen.com/subject/hpfvxqtx.html