1.模型

@class FriendsModel;

@interface GroupModel : NSObject

@property (nonatomic, copy) NSString *name;

@property (nonatomic, copy) NSString *online;

@property (nonatomic, strong) NSArray *friends;

@property (nonatomic, strong) FriendsModel *friendModel;

@property (nonatomic, assign) BOOL isOpen;

- (instancetype)initWithDict:(NSDictionary *)dict;

+ (instancetype)GroupWithDict:(NSDictionary *)dict;

@end

#import "FriendsModel.h"

@implementation GroupModel

- (instancetype)initWithDict:(NSDictionary *)dict{

if (self = [super init])
{

[self setValuesForKeysWithDictionary:dict];

NSMutableArray *muArray = [NSMutableArray array];

for (NSDictionary *dict in self.friends)
{

FriendsModel *model = [FriendsModel friendWithDict:dict];

[muArray addObject:model];

}

self.friends = muArray;

}

return self;

}

+ (instancetype)GroupWithDict:(NSDictionary *)dict

{

return [[self alloc] initWithDict:dict];

}

@end

@interface FriendsModel : NSObject

@property (nonatomic, copy) NSString *icon;

@property (nonatomic, copy) NSString *name;

@property (nonatomic, copy) NSString *intro;

@property (nonatomic, assign) BOOL isVip;

- (instancetype)initWithDict:(NSDictionary *)dict;

+ (instancetype)friendWithDict:(NSDictionary *)dict;

@end

#import "FriendsModel.h"

@implementation FriendsModel

- (instancetype)initWithDict:(NSDictionary *)dict{

if (self = [super init])
{

[self setValuesForKeysWithDictionary:dict];

}

return self;

}

+ (instancetype)friendWithDict:(NSDictionary *)dict{

return [[self alloc] initWithDict:dict];

}

@end


2.tableView UITableViewHeaderFooterView

的继承

@protocol HeaderViewDelegate <NSObject>

@optional

- (void)clickView;

@end

@interface HeaderView : UITableViewHeaderFooterView

@property (nonatomic,assign)id<HeaderViewDelegate>
delegate;

@property (nonatomic,strong) GroupModel *groupModel;

+ (instancetype)headerView:(UITableView *)tableView;

@end

#import "HeaderView.h"

#import “GroupModel.h"

@implementation HeaderView{

UIButton *_arrowBtn;

UILabel  *_label;

}

+ (instancetype)headerView:(UITableView *)tableView

{

staticNSString *identifier =@"header";

HeaderView *header = [tableViewdequeueReusableCellWithIdentifier:identifier];

if (!header) {

header = [[HeaderViewalloc]initWithReuseIdentifier:identifier];

}

return header;

}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier

{

if (self = [superinit]) {

UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

[button setBackgroundImage:[UIImageimageNamed:@"header_bg"]forState:UIControlStateNormal];

[button setBackgroundImage:[UIImageimageNamed:@"header_bg_highlighted"]forState:UIControlStateHighlighted];

[button setImage:[UIImageimageNamed:@"arrow"]forState:UIControlStateNormal];

[button setTitleColor:[UIColorblackColor]forState:UIControlStateNormal];

button.,,,
);

button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;

button.,,,
);

button.imageView.contentMode =UIViewContentModeCenter;

[button addTarget:selfaction:@selector(buttonAction)forControlEvents:UIControlEventTouchUpInside];

//超出范围的图片不要剪切

button.imageView.clipsToBounds =NO;

_arrowBtn = button;

[selfaddSubview:_arrowBtn];

//创建label,显示当前在线人数

UILabel *labelRight = [[UILabelalloc]init];

labelRight.textAlignment =NSTextAlignmentCenter;

_label = labelRight;

[selfaddSubview:_label];

}

return
self;

}

#pragma mark - buttonAction

- (void)buttonAction

{

self.groupModel.isOpen = !self.groupModel.isOpen;

if ([self.delegaterespondsToSelector:@selector(clickView)])
{

[self.delegateclickView];

}

}

- (void)didMoveToSuperview

{

//通知相关视图他们的上级视图已经变化是当某个子控件载入到父控件上得时候调用

_arrowBtn.imageView.transform =self.groupModel.isOpen ?

CGAffineTransformMakeRotation(M_PI_2)
:CGAffineTransformMakeRotation();

}

//布局

- (void)layoutSubviews

{

[superlayoutSubviews];

_arrowBtn.frame =self.bounds;

_label.frame =CGRectMake(self.frame.size.width
- ,
,self.frame.size.height);

}

//赋值

- (void)setGroupModel:(GroupModel *)groupModel

{

_groupModel = groupModel;

[_arrowBtn setTitle:_groupModel.name forState:UIControlStateNormal];

_label.text = [NSString stringWithFormat:@"%@/%lu",_groupModel.online,(unsignedlong)_groupModel.friends.count];

}

3.控制器

#import "ListTableViewController.h"

#import "GroupModel.h"

#import "FriendsModel.h"

#import "HeaderView.h"

#import "ViewController.h"

@interface
ListTableViewController ()<HeaderViewDelegate>

@property (nonatomic, strong)NSArray *dataArray;

@end

@implementation ListTableViewController

//懒载入

- (NSArray *)dataArray{

if (!_dataArray) {

NSString *path = [[NSBundlemainBundle]pathForResource:@"friends.plist"ofType:nil];

NSArray *array = [NSArrayarrayWithContentsOfFile:path];

NSMutableArray *muArray = [NSMutableArrayarrayWithCapacity:array.count];

for (NSDictionary *dictin array) {

GroupModel *groupModel = [GroupModel GroupWithDict:dict];

[muArray addObject:groupModel];

}

_dataArray = [muArraycopy];

}

return_dataArray;

}

- (void)viewDidLoad

{

[superviewDidLoad];

;//自己定义了sectionHeader一定要设置高

[selfclipExtraCellLine:self.tableView];//数据不够,去掉以下多余的表格线

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return
self.dataArray.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

GroupModel *groupModel =self.dataArray[section];

;

return count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath

{

staticNSString *identifier =@"friendCell";

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:identifier];

if (!cell) {

cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:identifier];

}

GroupModel *groupModel =self.dataArray[indexPath.section];

FriendsModel *friendModel = groupModel.friends[indexPath.row];

cell.imageView.image = [UIImage imageNamed:friendModel.icon];

cell.textLabel.text = friendModel.name;

cell.detailTextLabel.text = friendModel.intro;

return cell;

}

#pragma mark - UITableView delegate

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

HeaderView *header = [HeaderViewheaderView:tableView];

header.delegate =self;

header.groupModel =self.dataArray[section];

return header;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath

{

ViewController *viewCtrl = [[ViewControlleralloc]init];

//viewCtrl.view.backgroundColor = [UIColor redColor];

[self.navigationControllerpushViewController:viewCtrlanimated:NO];

}

- (void)clickView

{

[self.tableViewreloadData];

}

#pragma mark - 去掉多余的线

- (void)clipExtraCellLine:(UITableView *)tableView

{

UIView *view = [[UIViewalloc]init];

view.backgroundColor = [UIColorclearColor];

[self.tableViewsetTableFooterView:view];

}

/*

设置视图控制颜色

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

self.window.backgroundColor = [UIColor whiteColor];

ListTableViewController *listVC = [[ListTableViewController alloc] init];

UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:listVC];

self.window.rootViewController = navCtrl;

[self.window makeKeyAndVisible];

*/

素材下载地址:http://download.csdn.net/detail/baitxaps/8934111

QQList列表功能实现的更多相关文章

  1. nginx 目录文件列表功能配置

    工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果,而Nginx也可以满足这样的需求(nginx 目录列表功能默认是关闭的),这时就需要配置. ...

  2. HoverTree项目添加了查看留言列表功能

    HoverTree项目添加了查看留言列表功能 页面:HoverTreeWeb项目下hvtpanel/usermessage/messagelist.aspx 添加留言页面:addmessage.asx ...

  3. 【转】如何开启notepad++函数列表功能

    原文网址:http://jingyan.baidu.com/article/4b07be3c41e05e48b380f3f6.html Notepad++是window下特有的一款开源编辑器软件,相信 ...

  4. 开放Nginx在文件夹列表功能

    nginx在列出的默认同意整个文件夹.你怎么转Nginx在文件夹列表功能?打开nginx.conf文件.在location server 要么 http段增加 autoindex on;另外两个參数最 ...

  5. 微信小程序新闻列表功能(读取文件、template模板使用)

    微信小程序新闻列表功能(读取文件.template) 不忘初心,方得始终.初心易得,始终难守. 在之前的项目基础上进行修改,实现读取文件内容作为新闻内容进行展示. 首先,修改 post.wxml 文件 ...

  6. ListView实现丰富的列表功能

    ListView实现丰富的列表功能 1.主布局activity_main.xml <?xml version="1.0" encoding="utf-8" ...

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

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

  8. 13、Django实战第13天:分页列表功能

    我们看课程 机构列表页是需要分页的 为了完成分页功能,我们需要用到Django的一个开源开发库django-pure-pagination workon mxonline pip install dj ...

  9. 基于SpringBoot从零构建博客网站 - 分页显示文章列表功能

    显示文章列表一般都是采用分页显示,比如每页10篇文章显示.这样就不用每次就将所有的文章查询出来,而且当文章数量特别多的时候,如果一次性查询出来很容易出现OOM异常. 后台的分页插件采用的是mybati ...

随机推荐

  1. SGU 101 Domino (输出欧拉路径)

    101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB Dominoes – game played wit ...

  2. There are no packages available for install

    解决方法: ·删除sublime Text 安装目录下Data->Packages目录下的Package Control(如果没有,略过此步骤). ·下载Package Control,下载路径 ...

  3. 读写分离,读写分离死锁解决方案,事务发布死锁解决方案,发布订阅死锁解决方案|事务(进程 ID *)与另一个进程被死锁在 锁 资源上,并且已被选作死锁牺牲品。请重新运行该事务

    前言:         由于网站访问压力的问题,综合分析各种因素后结合实际情况,采用数据库读写分离模式来解决当前问题.实际方案中采用“事务发布”模式实现主数据库和只读数据库的同步,其中: 发布服务器1 ...

  4. [Deepin 15] 安装 Java 8、Git、Firefox、SafeEyes(定时提醒休息工具)

    一.安装 JDK 8 1.到官网,用 迅雷下载 安装包 (jdk-8u131-linux-x64.tar.gz) 2.解压放到目录 /opt/software/jdk 3.配置环境变量 sudo vi ...

  5. Golang 版本发布 与 TIOBE 排名

    2016年国庆节(10月1日)开始接触 Go 语言,记录一下它的 版本发布 与 TIOBE 排名: Golang 排行榜 月份 版本 排名 备注 2012.03 1.0             201 ...

  6. Golang 特性简介

    by sheepbao 主要大概介绍go语言的历史和特性,简单的入门. 来历 很久以前,有一个IT公司,这公司有个传统,允许员工拥有20%自由时间来开发实验性项目.在2007的某一天,公司的几个大牛, ...

  7. SpringBoot配置多数据源

    原文:https://www.jianshu.com/p/033e0ebeb617 项目中用到了两个数据库,分别是Oracle和Mysql,涉及到了多数据源问题,这里做下记录 官方讲解:https:/ ...

  8. mormot事务控制

    mormot事务控制 mormot对所有的数据库类型事务都是一样处理方法gProps.SharedTransaction(1, transBegin);try gProps.SharedTransac ...

  9. Maven settings配置中的mirrorOf

    原文地址:http://blog.csdn.net/isea533/article/details/21560089 使用maven时,从来没仔细注意过setting配置节点的作用,直到今天配置总是不 ...

  10. 倒计时相关函数 php

    <script type="text/javascript" language="javascript"> function datetime_to ...