QQ分组效果
来源:互联网 发布:大数据时代营销 编辑:程序博客网 时间:2024/04/30 06:49
tableView简单实现qq分组的效果
定义一个BOOL类型的数组,count要大于要分的组数
首先定义有多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _data.count;
}
//返回相应组里面有多少个单元格
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *array2D = _data[section];
BOOL isClose = close[section];
if (isClose) {
return 0;
}
return array2D.count;
}
//创建每一个单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *iden =@"cell";
//从闲置池中取单元格
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:iden];
if (cell == nil) {
cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:iden] autorelease];
}
/*data的样式:
[
[@"字体1",@"字体2",@"字体3",@"字体4",@"字体5"], 第一组
[@"字体1",@"字体2",@"字体3"], 第二组
[@"字体1",@"字体2",@"字体3",@"字体4"],
....
]
*/
//取得组
NSInteger section = indexPath.section;
NSArray *array2D = _data[section];
//添加数据
cell.textLabel.text = array2D[indexPath.row];
return cell;
}
通过代理方法设置头视图,需要确定组的头视图高度,否则不会显示头视图
//设置组的头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//创建按钮
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
//设置tag
button.tag = section;
NSString *title = [NSStringstringWithFormat:@"好友分组%ld",section];
[button setTitle:titleforState:UIControlStateNormal];
[button setBackgroundImage:[UIImageimageNamed:@"tableCell_common"]forState:UIControlStateNormal];
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
return button;
}
button的点击事件
- (void)buttonAction:(UIButton *)button {
//取得点击的组
NSInteger section = button.tag;
close[section] = !close[section];
//刷新视图
// [_tableView reloadData];
//刷新指定的组
NSIndexSet *indexSet = [NSIndexSetindexSetWithIndex:section];
[_tableViewreloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
}
//设置组的头视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44;
}
- QQ分组效果
- Android实现QQ分组效果
- iOS仿QQ分组效果
- android仿qq分组列表效果
- QQ分组效果(ExpandableListView)的使用
- 仿QQ好友列表分组折叠效果
- android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(一)
- android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(二)
- android 仿qq好友列表分组效果及联系人分组效果
- UITableView的折叠收缩和QQ好友分组效果
- UITableView的折叠收缩和QQ好友分组效果
- UITableView的折叠收缩和QQ好友分组效果
- QQ 分组
- QQ分组
- qq分组
- Android: listview 分组上滑标题碰撞效果,固定标题效果,仿QQ微信
- ExpandableListView实例(三)_实现QQ中"未分组"效果和"未分组"不可编辑删除功能
- 仿qq联系人分层list&&分组悬浮向上滚动效果 最简化demo
- metasploit - meterpreter commands (windows)
- 欢迎使用CSDN-markdown编辑器
- 第十课:编程基础(二)
- oracle到底能不能insert into 多个values!?
- Protobuf的奇怪问题解决--Expected top - level statement (e.g "message")
- QQ分组效果
- android handler,looper,MessageQueue理解
- 物联网学习总结
- deflate算法总结
- JMS 学习第二章
- sed高级用法:模式空间(pattern space)和保持空间(hold space)
- 一切从ServerBootstrap开始
- sqlite多表关联
- POJ2752 Seek the Name, Seek the Fame【KMP】