1.聲明屬性和代理
<UITableViewDataSource>
{
BOOL _flagArr[100];
NSArray *_array;
}
@property(nonatomic,strong)UITableView *tableView;
2.創(chuàng)建tableview
- (void)createTableView{
_array = @[@"驢友",@"牌友黨",@"大學(xué)同學(xué)",@"非好友"];
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.實(shí)現(xiàn)代理和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-伸縮表實(shí)現(xiàn)(QQ列表模式)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 在實(shí)際開(kāi)發(fā)中,我們用的最多的控件可以說(shuō)非UITableView莫屬了,我們使用UITableView來(lái)展示一系列類...
- 功能簡(jiǎn)介 每一行cell跳轉(zhuǎn)一個(gè)不同的頁(yè)面。例如: 解決方法 第一種 很多人都會(huì)用if-else來(lái)進(jìn)行判斷,這樣即...
- 有一種小確喪的根源叫:賴床不到最后一刻都不算賴! 起床從來(lái)都不按時(shí)起,與睡覺(jué)時(shí)的我暗自約定好一直拖到最后一刻。一般...
- 年初制定了我的年度目標(biāo),包括了八大關(guān)注,其中一項(xiàng)關(guān)注是學(xué)習(xí)模塊,下面有一個(gè)讀書計(jì)劃,我最初制定的目標(biāo)是...