思路:
1、创建一个样式为plain的tableView;
2、返回多个section;
3、返回多个row;
4、设置tableHeadView的背景色(解决方法:在 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 中创建一个UI View,并设置其背景色,再在其添加UILabel,返回UI View对象);
代码:
_deviceStateTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 80, UISCREEN_WIDTH, UISCREEN_HEIGHT-64) style:UITableViewStylePlain];
_deviceStateTableView.delegate = self;
_deviceStateTableView.dataSource = self;
_deviceStateTableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_deviceStateTableView];
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, 30)];
view.backgroundColor = self.view.backgroundColor;
UILabel *time = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, UISCREEN_WIDTH, 30)];
time.text = [[[Bdx_note getDeviceArr]objectAtIndex:section]objectForKey:@"time"];
[view addSubview:time];
return view;
}