plain风格区头悬浮显示;grouped风格则区头跟随表格滑动
代码:
#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tab;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *tab = [[UITableViewalloc]initWithFrame:self.view.boundsstyle:UITableViewStylePlain];
[self.viewaddSubview:tab];
tab.delegate =self;
tab.dataSource =self;
[tab registerClass:[UITableViewCellclass]forCellReuseIdentifier:@"cell"];
self.tab = tab;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];
cell.textLabel.text = [NSStringstringWithFormat:@"分区:%ld___行:%ld",indexPath.section,indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return30;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *aView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width,30)];
aView.backgroundColor = [UIColoryellowColor];
return aView;
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end