ios中tableview的创建和自定义cell的封装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/helloworld183/article/details/79804585

#import "HGYwaitServiceViewController.h"

#import "HGYWaitingserveCell.h"

@interface HGYwaitServiceViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@end


@implementation HGYwaitServiceViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = HGYGlobalBackgroundColor;

    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, self.view.frame.size.height-100) style:UITableViewStyleGrouped];

    _tableView.delegate = self;

    _tableView.dataSource = self;

    _tableView.backgroundColor = HGYGlobalBackgroundColor;

    _tableView.separatorStyle = UITableViewCellSelectionStyleNone;

    [self.view addSubview:_tableView];

}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    UIView *view = [[UIView alloc]init];

    return view;

}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *view = [[UIView alloc]init];

    return view;

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 5;

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 5;

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 2;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    HGYWaitingserveCell *servecell = [HGYWaitingserveCell cellWithTableView:tableView];

    return servecell;

}

@end

//自定义cell的的封装

#import <UIKit/UIKit.h>


@interface HGYWaitingserveCell : HGYBaseCell

+(instancetype)cellWithTableView:(UITableView *)tableView;

@end

#import "HGYWaitingserveCell.h"


@implementation HGYWaitingserveCell

+(instancetype)cellWithTableView:(UITableView *)tableView{

    static NSString *ID = @"HGYWaitingserveCell";

    id cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (cell==nil) {

         cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];    }

    return cell;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        self.backgroundColor = [UIColor redColor];

    }

    return self;

}

@end



猜你喜欢

转载自blog.csdn.net/helloworld183/article/details/79804585