#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好友列表视图的更多相关文章

  1. android开发之ExpandableListView的使用,实现类似QQ好友列表

    由于工作需要,今天简单研究了一下ExpandableListView,做了一个类似QQ列表的Demo,和大家分享一下. 效果图如下: 先来看看主布局文件: <RelativeLayout xml ...

  2. [iOS基础控件 - 6.9.3] QQ好友列表Demo TableView

    A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组   code so ...

  3. swift 实现QQ好友列表功能

    最近项目中有类似QQ好友列表功能,整理了一下,话不多说,直接上代码 import UIKit class QQFriend: NSObject { var name: String? var intr ...

  4. ExpandableListView仿QQ好友列表

    本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...

  5. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

    iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...

  6. (二十七)QQ好友列表的实现

    QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...

  7. 仿QQ好友列表界面的实现

    TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style ...

  8. android 实现QQ好友列表

    在某些Android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的.接触Android,也才一年的时间,大部分时间花在工作上(解bug...),界面上开发很少参与.自己维护的系统应用 ...

  9. C#利用API制作类似QQ一样的右下角弹出窗体

    C#利用API制作类似QQ一样的右下角弹出窗体 (2009-03-21 15:02:49) 转载▼ 标签: 杂谈 分类: .NET using System;using System.Collecti ...

随机推荐

  1. 【VS2013编译DirectX Tutorials时遇到的错误】FXC : error X3501: 'main': entrypoint not found

    修改于2015年9月6日: 去年写这篇解决方案的时候其实对着色器编程还一知半解,摸索了一个治标不治本的方法解决问题,结果被一个CSDN的博主原封不动抄了去,还打上个原创的标签= =,简直无语... 最 ...

  2. GEF入门实例_总结_06_为编辑器添加内容

    一.前言 本文承接上一节:GEF入门实例_总结_05_显示一个空白编辑器 在上一节我们为我们的插件添加了一个空白的编辑器,这一节我们将为此编辑器添加内容. 二.GEF的MVC模式 在此只简单总结一下, ...

  3. DataGridView绑定数据源的几种方式

    使用DataGridView控件,可以显示和编辑来自多种不同类型的数据源的表格数据. 将数据绑定到DataGridView控件非常简单和直观,在大多数情况下,只需设置DataSource属性即可.在绑 ...

  4. linux命令学习笔记(30): chown命令

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID: 文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷 ...

  5. I.MX6 make menuconfig进入x86模式

    /************************************************************************ * I.MX6 make menuconfig进入x ...

  6. tag问题

  7. 寻找数组中第K大数

    1.寻找数组中的第二大数 using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  8. jsp中引入JavaScript的方法

    1:在页面中直接嵌入JavaScript <script language="javascript">..........</script> 2:链接外部J ...

  9. Websphere中的几个常用概念

    什么是单元(Cell)?什么是节点(Node)?Node.Profile 与 Server 之间的关系是什么? 答: 单元: 单元是整个分布式网络中一个或多个节点的逻辑分组.单元是一个配置概念,是管理 ...

  10. GMchess Linux下的中国象棋游戏

    gmchess,一款Linux下的中国象棋程序