1.准备 2.简单设置 // 两种类型 一般Plain 不设置默认为Plain // typedef NS_ENUM(NSInteger, UITableViewStyle) { // UI
1.准备
2.简单设置
// 两种类型 一般Plain 不设置默认为Plain
// typedef NS_ENUM(NSInteger, UITableViewStyle) {
// UITableViewStylePlain, // regular table view
// UITableViewStyleGrouped // preferences style table view
// };
_tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
[self.view addSubview:_tableView];
// 设置代理和数据来源
_tableView.delegate = self;
_tableView.dataSource = self;
// 注册方式
// [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellID];
3.代理方法实现和复用
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// return 3;//3组
return self.dataList.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// return 5;//每组5个ROW,可以对section进行判断来分别设置几个ROW
return [self.dataList[section] count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// 设置高度
return 78.0f;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
// 复用机制
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
// UI可以复用 数据不能 如果是注册这里就不写
}
cell.textLabel.text = self.dataList[indexPath.section][indexPath.row];
return cell;
}