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.contentEdgeInsets =UIEdgeInsetsMake(0,10,0, 0);

button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;

button.titleEdgeInsets =UIEdgeInsetsMake(0,10,0, 0);

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(0);

}

//布局

- (void)layoutSubviews

{

[superlayoutSubviews];

_arrowBtn.frame =self.bounds;

_label.frame =CGRectMake(self.frame.size.width - 70, 0, 60,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];

self.tableView.sectionHeaderHeight =40;//自己定义了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];

NSInteger count = groupModel.isOpen ? groupModel.friends.count :0;

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

转载于:https://www.cnblogs.com/gccbuaa/p/7391243.html

QQList列表功能实现相关推荐

  1. 为啥我从后台查到的值在页面显示的是undefined_再谈一个管理后台列表功能应有的素质...

    ​大家能看到的这个号第1篇文章<无心朝政,列表功能分析下>就是讲列表功能.虽然当时写的时候特别认真,但基本是围绕"列表功能"这个广泛的词来阐述的. 最近在做一个体育赛事 ...

  2. redis+php微博,redis+php实现微博(三)微博列表功能详解

    本文实例讲述了redis+php实现微博列表功能.分享给大家供大家参考,具体如下: 个人主页显示微博列表(自己及关注人的微博列表) /*获取最新的50微博信息列表,列出自己发布的微博及我关注用户的微博 ...

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

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

  4. iphone html阅读,iPhone如何使用Safari浏览器阅读列表功能

    在 iPhone 自带的 Safari 浏览器中,有一项实用的功能叫做"阅读列表",可以储存您想要继续阅览的网页.并且当您为浏览器开启 iCloud 功能之后,添加到阅读列表中的页 ...

  5. android的实现关注好友功能,android仿微信好友列表功能

    android studio实现微信好友列表功能,注意有一个jar包我没有放上来,请大家到MainActivity中的那个网址里面下载即可,然后把pinyin4j-2.5.0.jar复制粘贴到项目的a ...

  6. 2021 Vue全家桶开发电商管理系统(Element-UI)08 商品列表功能的实现

    商品列表功能的实现 1 自定义格式化时间的全局过滤器 打开main.js,创建过滤器 Vue.filter('dateFormat', function (originVal) {const dt = ...

  7. 通用列表功能使用方法和API

    通用列表功能使用方法和API 通用列表功能使用方法 分组 功能同Excel的分类汇总功能:根据选择的列进行分类:并且可以结合∑功能实现分类汇总功能. ∑功能 功能同Excel的∑功能:如求最大值.最小 ...

  8. 云上铺会员管理系统会员列表功能与说明

    云上铺会员管理系统,会员列表功能,包含新增会员,编辑会员,会员信息筛选查询,业务管理,删除会员,导出会员信息,指定会员发送营销短信等功能. 一:会员筛选条件.进入会员管理-会员列表,点击筛选条件. 会 ...

  9. 在后台实现按照状态查询订单列表功能

    文章目录 在后台实现按照状态查询订单列表功能 需求 在left.jsp页面添加五个节点 AdminOrderServlet服务器中的findAllByState方法 service层的findAllB ...

最新文章

  1. 服务器项目带文件名,tomcat服务器上webapps里的文件名和项目名称不一样,修改方法...
  2. 软件构建之链接应用--链接脚本
  3. DP专练1( [NOIP 2003]加分二叉树 + 太空梯 )
  4. [转载]UEditor报错TypeError: me.body is undefined
  5. beforeRouteEnter,beforeRouteLeave函数
  6. 02326 操作系统 简答题 超简短归纳
  7. Java银行类编程题
  8. python中字符串格式化符号含义
  9. C++之继承探究(五):子类对象作父类对象使用
  10. 转:过度疲劳的27个信号与预防方法
  11. ORB_SLAM3在ubuntu18.04安装和初步测试+轨迹评估
  12. 在arcgis中进行拓扑检查
  13. 131多机型解码擦除工具
  14. 本人累计多年整理的所有软件 需要请留言 适合毕业设计参考
  15. layui导出Excel功能的两种方式的尝试
  16. 手机本地文档文件不能扫描出来的问题
  17. Cluster vs Clustering
  18. RJ45网线接头的引脚定义和制作方法
  19. JQuery动画基础:上卷下拉
  20. hadoop完全分布+hive数据分析

热门文章

  1. sx1268 中文_STM32开发笔记85: SX1268驱动程序设计(芯片唤醒)
  2. html tab与jQuery,使用jquery实现div的tab切换实例代码
  3. html插入flash代码_初学者必备Web开发APP,支持代码补全,一键插入代码,厉害了!...
  4. JS面向对象——Object.defineProperty
  5. WIN 10 安装 Hadoop 2.7.7 + Spark 2.4.7 记录
  6. LeetCode 1806. 还原排列的最少操作步数(模拟)
  7. LeetCode 385. 迷你语法分析器(栈)
  8. LeetCode 241. 为运算表达式设计优先级(动态规划)
  9. 程序员面试金典 - 面试题 03.05. 栈排序(两栈)
  10. LeetCode 165. 比较版本号