美文网首页
自定义表格

自定义表格

作者: 自知则知 | 来源:发表于2018-11-21 14:34 被阅读0次

#import "TableViewCell.h"

@interface ViewController ()<UITableViewDelegate , UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

    _tableView.dataSource = self;

    _tableView.delegate = self;

    [self.viewaddSubview:self.tableView];

    [_tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];

}

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

    return 2;

}

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

    staticNSString*string =@"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];

    if(!cell) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string];

    }

    return cell;

}

相关文章

网友评论

      本文标题:自定义表格

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