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來進行判斷,這樣即...
- 有一種小確喪的根源叫:賴床不到最后一刻都不算賴! 起床從來都不按時起,與睡覺時的我暗自約定好一直拖到最后一刻。一般...