1.声明属性和代理
<UITableViewDataSource>
{
BOOL _flagArr[100];
NSArray *_array;
}
@property(nonatomic,strong)UITableView *tableView;
2.创建tableview
- (void)createTableView{
_array = @[@"驴友",@"牌友党",@"大学同学",@"非好友"];
UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 72+HEIGHT/16+10, WIDTH, 2)];
line.backgroundColor = SLIVERYCOLOR;
[self.view addSubview:line];
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 72+HEIGHT/16+10+2, WIDTH, HEIGHT-84-HEIGHT/16)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = 50;
[self.view addSubview:self.tableView];
}
3.实现代理和datasource方法
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return _array.count;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return HEIGHT/14;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/14)];
sectionView.backgroundColor = [UIColor whiteColor];
[self.tableView addSubview:sectionView];
UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT/14-2, WIDTH, 2)];
line.backgroundColor = SLIVERYCOLOR;
[sectionView addSubview:line];
UIImageView * arrow = [[UIImageView alloc]initWithFrame:CGRectMake(15, (HEIGHT/14-15)/2, 15, 15)];
[arrow setImage:[UIImage imageNamed:@"contacts_arrow.png"]];
if (_flagArr[section]) {
arrow.transform = CGAffineTransformMakeRotation(M_PI_2);
}else{
arrow.transform = CGAffineTransformIdentity;
}
[sectionView addSubview:arrow];
UILabel *groupLab = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, WIDTH/2-35, HEIGHT/14)];
groupLab.text = _array[section];
groupLab.textColor = TEXTCOLOR;
groupLab.font = [UIFont systemFontOfSize:13];
groupLab.textAlignment = NSTextAlignmentLeft;
[sectionView addSubview:groupLab];
UILabel *numLab = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/2, 0, WIDTH/2-43, HEIGHT/14)];
numLab.text = @"8/13";
numLab.textColor = TEXTCOLOR;
numLab.font = [UIFont systemFontOfSize:13];
numLab.textAlignment = NSTextAlignmentRight;
[sectionView addSubview:numLab];
UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
deleteBtn.frame = CGRectMake(WIDTH-33, (HEIGHT/14-18)/2, 18, 18);
deleteBtn.layer.cornerRadius = 9;
deleteBtn.clipsToBounds = YES;
[deleteBtn setImage:[UIImage imageNamed:@"fenzu.png"] forState:UIControlStateNormal];
deleteBtn.adjustsImageWhenHighlighted = NO;
[deleteBtn addTarget:self action:@selector(deleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:deleteBtn];
UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
clickBtn.frame = CGRectMake(0, 0, WIDTH-35,HEIGHT/14);
clickBtn.layer.cornerRadius = 9;
clickBtn.tag = 180 + section;
clickBtn.clipsToBounds = YES;
clickBtn.adjustsImageWhenHighlighted = NO;
[clickBtn addTarget:self action:@selector(clickBtnBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:clickBtn];
return sectionView;
}
- (void)deleteBtnClick:(UIButton *)sender{
}
- (void)clickBtnBtnClick:(UIButton *)sender{
_flagArr[sender.tag-180] = !_flagArr[sender.tag-180];
[self.tableView reloadData];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (_flagArr[section]) {
return 3;
}else{
return 0;
}
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellID = @"ForbidGroupTableViewCell";
ForbidGroupTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[[NSBundle mainBundle]loadNibNamed:cellID owner:self options:nil]lastObject];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell.deleBtn setImage:[UIImage imageNamed:@"fenzu.png"] forState:UIControlStateNormal];
[cell.headImage setImage:[UIImage imageNamed:@"wb_binding.png"]];
cell.nameLab.text = @"呵呵";
cell.signLab.text = @"阿弥陀佛";
return cell;
}
iOS-伸缩表实现(QQ列表模式)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 在实际开发中,我们用的最多的控件可以说非UITableView莫属了,我们使用UITableView来展示一系列类...
- 功能简介 每一行cell跳转一个不同的页面。例如: 解决方法 第一种 很多人都会用if-else来进行判断,这样即...
- 有一种小确丧的根源叫:赖床不到最后一刻都不算赖! 起床从来都不按时起,与睡觉时的我暗自约定好一直拖到最后一刻。一般...