1. 纯代码创建
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor grayColor];
//style:UITableViewStyleGrouped 分组
//style:UITableViewStylePlain 当组名称滑动到顶部时,将固定在顶部位置
UITableView *tabview = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
tabview.backgroundColor = [UIColor yellowColor];
tabview.dataSource = self;
[self.view addSubview:tabview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 5;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [NSString stringWithFormat:@"分组%zd", section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 6;
}
- (UI