iOS UITableView制作类似QQ好友列表视图

#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
self.window.rootViewController = navi; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
#import "RootViewController.h" @interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableView;
NSMutableDictionary *dataDic;
}
@end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
// 初始化_tableView
[self initializeTableView];
// 加载数据
[self loadData];
}
/**
* 初始化_tableView
*/
- (void)initializeTableView
{
_tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStyleGrouped];
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
}
/**
* 加载数据
*/
- (void)loadData
{
// 数组的第一个对象为标志位(是否展开)
NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:@"",@"apple",@"alex",@"alert",@"awake", nil];
NSMutableArray *arr2 = [NSMutableArray arrayWithObjects:@"",@"blance",@"bank",@"baby",@"bet",@"balance", nil];
NSMutableArray *arr3 = [NSMutableArray arrayWithObjects:@"",@"cake",@"cat",@"caught",@"cell",@"clabe", @"cry",@"cave",nil];
NSMutableArray *arr4 = [NSMutableArray arrayWithObjects:@"",@"dog",@"data",@"date",@"drive",@"down", @"deliver",@"dire",@"drawn",@"dety",@"depature",@"dom",nil];
NSMutableArray *arr5 = [NSMutableArray arrayWithObjects:@"",@"elphance",@"eleven",@"every",nil];
// 把对应的数据存入字典
dataDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:arr1,@"A",arr2,@"B",arr3,@"C",arr4,@"D",arr5,@"E", nil] ;
} #pragma mark - UITableViewDataSource And UITableViewDelegate -
// 返回的表头个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[dataDic allKeys] count];
}
// 每个表头返回对应的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 因为字典是无序的,通过比较来进行排序
NSArray *keys = [[dataDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSString *key = keys[section];
NSMutableArray *array = dataDic[key];
NSString *IsExpand = array[];
// 如果为“1”则返回相应的行数,否则返回0
if ([IsExpand isEqualToString:@""]) {
// 因为数组的第一位为标志位所以减1
return ([array count] - );
}
return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, )];
view.backgroundColor = [UIColor colorWithRed: green: blue: alpha:];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width - , )];
label.font = [UIFont systemFontOfSize:];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
NSArray *keys = [[dataDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
label.text = keys[section];
[view addSubview:label];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , [UIScreen mainScreen].bounds.size.width, );
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button.tag = + section;
[view addSubview:button];
return view;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
NSArray *keys = [[dataDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSString *key = keys[indexPath.section];
NSMutableArray *array = dataDic[key];
// 由于数组的第一位是标志位,且不用显示,所以加1
NSString *textStr = array[indexPath.row + ];
cell.textLabel.text = textStr;
return cell;
} #pragma mark -Target Action-
/**
* 点击表头,如果没有展开,则展开;如果已经展开,则关闭
*/
- (void)buttonAction:(UIButton *)sender
{
long section = sender.tag - ;
NSArray *keys = [[dataDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSString *key = keys[section];
NSMutableArray *array = dataDic[key];
NSString *IsExpand = array[];
// 如果IsExpand等于“0”(关闭状态),则展开,且设置其值为“1”;相反,如果IsExpand等于“1”(展开状态),则关闭,且设置其值为“0”
if ([IsExpand isEqualToString:@""]) {
array[] = @"";
}else{
array[] = @"";
}
[_tableView reloadData];
}
@end
iOS UITableView制作类似QQ好友列表视图的更多相关文章
- android开发之ExpandableListView的使用,实现类似QQ好友列表
由于工作需要,今天简单研究了一下ExpandableListView,做了一个类似QQ列表的Demo,和大家分享一下. 效果图如下: 先来看看主布局文件: <RelativeLayout xml ...
- [iOS基础控件 - 6.9.3] QQ好友列表Demo TableView
A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组 code so ...
- swift 实现QQ好友列表功能
最近项目中有类似QQ好友列表功能,整理了一下,话不多说,直接上代码 import UIKit class QQFriend: NSObject { var name: String? var intr ...
- ExpandableListView仿QQ好友列表
本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
- (二十七)QQ好友列表的实现
QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...
- 仿QQ好友列表界面的实现
TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style ...
- android 实现QQ好友列表
在某些Android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的.接触Android,也才一年的时间,大部分时间花在工作上(解bug...),界面上开发很少参与.自己维护的系统应用 ...
- C#利用API制作类似QQ一样的右下角弹出窗体
C#利用API制作类似QQ一样的右下角弹出窗体 (2009-03-21 15:02:49) 转载▼ 标签: 杂谈 分类: .NET using System;using System.Collecti ...
随机推荐
- 基于vue的滚动条组件之--element隐藏组件滚动条scrollbar使用
在项目中,总是需要用到滚动条,但windows浏览器默认的滚动条是很丑的,为了页面美观,可以考虑优化滚动条样式. vue Element UI官方文档上并没有放出滚动条相关的示例说明,但是实际上是有 ...
- 分布式_理论_08_Consistent Hash(一致性哈希算法)
一.前言 五.参考资料 1.分布式理论(八)—— Consistent Hash(一致性哈希算法)
- 条款36:绝对不要重新定义,继承而来的non-virtual函数
重新定义一个继承而来的non-virtual函数可能会使得导致当函数被调用的时候,被调用的函数不是取决于调用的函数究竟属于的对象,而是取决于调用函数的指针或者引用的类型. 所以一般的说主要有两种观点在 ...
- Struts2(2)
一.分模块开发:单独写模块的配置文件,把配置文件引入到核心配置文件中 Aaction的单独配置文件如下 <?xml version="1.0" encoding=" ...
- Linux-软件安装管理
1.软件包分类 源码包:脚本安装包 二进制包:RPM包.系统默认包 2.rpm命令管理 @rmp包在系统光盘中 mkdir /mnt/cdrom mount /dev/sr0 /mnt/cdrom c ...
- CodeSmith 基本语法(二)
CodeSmith之四 - 典型实例(四) CodeSmith API文档 (三) CodeSmith 基本语法(二) CodeSmith 图形界面基本操作(一) CodeSmith的C#语法与Asp ...
- Road to OI
我学OI已经三年有余了.回首向来萧瑟处,在镜花水月一般的OI生涯面前,我不敢,也没资格称“也无风雨也无晴”.这三年我过得浑浑噩噩,玩了很多游戏,看了很多番,追过一个女孩,OI却搞得一塌糊涂.留给我的时 ...
- sleep(0)作用
假设现在是 2008-4-7 12:00:00.000,如果我调用一下 Thread.Sleep(1000) ,在 2008-4-7 12:00:01.000 的时候,这个线程会 不会被唤醒?某人的代 ...
- Mysql 5.6 MHA (gtid) on Kylin
mha on Kylinip hostname repl role mha role192.168.19.69 mysql1 master node192.168.19.73 mysql2 slave ...
- Celery-4.1 用户指南: Canvas: Designing Work-flows(设计工作流程)
签名 2.0 版本新特性. 刚刚在calling 这一节中学习了使用 delay 方法调用任务,并且通常这就是你所需要的,但是有时候你可能想将一个任务调用的签名传递给另外一个进程或者作为另外一个函数的 ...