#import <Foundation/Foundation.h>
@interface tableData : NSObject
@property (nonatomic,copy)NSString * title;
@property (nonatomic,strong)NSMutableArray * array;
@property (nonatomic,assign,readwrite)BOOL isShow;
@end
#import "aboutViewController.h"
#import "Header.h"
#import "tableData.h"
@interface aboutViewController ()<UITableViewDataSource,UITableViewDelegate>{
NSMutableArray * dataArray;
}
@property (nonatomic,strong)UITableView * infoTableView;
@end
@implementation aboutViewController
-(instancetype)init{
if (self = [super init]) {
dataArray = [NSMutableArray array];
for (int i = 'A'; i <= 'Z' ; i++) {
tableData * data = [[tableData alloc]init];
data.title = [NSString stringWithFormat:@"%d",i];
for (int a = 0; a<6; a++) {
[data.array addObject:[NSString stringWithFormat:@"%d",a]];
}
[dataArray addObject:data];
}
}
return self;
}
-(void)setInfoTableView:(UITableView *)infoTableView{
if (_infoTableView != infoTableView) {
_infoTableView = infoTableView;
_infoTableView.dataSource =self;
_infoTableView.delegate =self;
[self.view addSubview:_infoTableView];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setData];
[self setUI];
}
-(void)setData{
}
-(void)setUI{
self.view.backgroundColor = [UIColor grayColor];
UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCR_WIDTH, SCR_HEIGHT) style:UITableViewStylePlain];
self.infoTableView = tableView;
}
#pragma mark tableView 代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if ([[dataArray objectAtIndex:section] isShow]) {
return [[[dataArray objectAtIndex:section] array] count];
}else{
return 0;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * cellid = @"cellid";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
}
cell.textLabel.text = @"test";
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"%@",indexPath);
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCR_WIDTH, 30)];
label.backgroundColor = [UIColor orangeColor];
label.tag = 1000 + section;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
label.userInteractionEnabled = YES;
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[label addGestureRecognizer:tap];
label.text = @"点我";
return label;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if ([[dataArray objectAtIndex:section] isShow]) {
return 0;
}else{
return 1;
}
}
-(void)tapClick:(UITapGestureRecognizer*)sender{
UILabel * label = (UILabel *)sender.view;
int tag = label.tag - 1000;
tableData * data = [dataArray objectAtIndex:tag];
data.isShow = !data.isShow;
[dataArray replaceObjectAtIndex:tag withObject:data];
[self.infoTableView reloadData];
}
@end