QQ分组
来源:互联网 发布:软件质量管理工程师 编辑:程序博客网 时间:2024/04/30 07:33
//要做分组最主要的就是控制tableView头视图的展开和收起,所以就必须要有布尔值来判断是展开还是收缩
BOOL close[16]; // NO表示展开 , YES表示收起
1.创建表视图;
_tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,20, 375, 647)style:UITableViewStylePlain];
_tableView.delegate =self;
_tableView.dataSource =self;
//组的头视图高度
_tableView,rowHeight = 44;
[self.viewaddSubview:_tableView];
//读取本地数据
NSString *filePath = [[NSBundlemainBundle] pathForResource:@"font.plist"ofType:nil];
//初始化数组
_data = [[NSArrayalloc] initWithContentsOfFile:filePath];
2.写代理方法
组的个数
- (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];
}
//取得组
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 setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
//button点击事件
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
return button;
}
- (void)buttonAction:(UIButton *)button {
//取得点击的组
NSInteger section = button.tag;
取反
close[section] = !close[section];
[_tableView reloadData];
//刷新指定的组
NSIndexSet *indexSet = [NSIndexSetindexSetWithIndex:section];
[_tableViewreloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
}
效果图如下:
- QQ 分组
- QQ分组
- qq分组
- QQ分组思路
- QQ分组效果
- QQ 分组界面
- QQ分组图案
- android 仿qq分组
- 类似qq分组栏-动态分组
- QQ里分组红名啥意思?
- Android实现QQ分组效果
- QQ 添加分组 添加好友
- 类似QQ好友分组栏
- iOS仿QQ分组效果
- QQ分组控件的简单实现
- QQ分组控件的简单实现
- Android之实现QQ好友分组(ExpandableListView)
- Android之实现QQ好友分组(ExpandableListView)
- 黑马程序员---------网络编程
- View Debugging in Xcode 6
- BZOJ3064: Tyvj 1518 CPU监控
- makefile和Cmakelist.txt的区别
- 用hibernate向mysql插入数据时问号乱码的问题解决!!
- QQ分组
- linux 命令系列之目录处理命令(2)
- (一)暗黑之光RPG游戏实战心得
- PS学习第二天
- qt事件过滤器
- js弹出新窗口
- Android事件总线 ( AndroidEventBus ) 框架发布
- 博客的第一天
- 如何在eclipse两个项目之间进行调用