QQList列表功能实现

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 allocinitWithDict:dict];

}


@end


@interface FriendsModel : NSObject


@property (nonatomiccopyNSString *icon;

@property (nonatomiccopyNSString *name;

@property (nonatomiccopyNSString *intro;

@property (nonatomicassignBOOL 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 allocinitWithDict: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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/487763.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

探臻实录 | 戴琼海:搭建脑科学与人工智能的桥梁

来源&#xff1a;探臻科技评论人工智能作为21世纪最具有影响力的技术&#xff0c;正在包括诸如机器人、语言识别、图像识别、自然语言处理等诸多领域发挥着重要作用。脑科学被誉为“人类科学最后的前沿”&#xff0c;认识脑的奥秘是对人类的终极挑战。而更重要的是&#xff0c;…

linux下的单机工具,Linux下单机模式的Hadoop部署

需要软件&#xff1a;ssh&#xff1a;fedore 9 自带。jdk&#xff1a;http://java.sun.com/javase/downloads/index.jsp&#xff0c;下最近版本jdk-6u18-linux-i586Hadoop&#xff1a;http://apache.etoak.com/hadoop/core/hadoop-0.20.1/&#xff0c;最新版本0.20.1&#xff0…

全球顶尖计算机科学家排名,中科大上榜人数全国第一

来源&#xff1a;今日头条一年一度的全球顶尖计算机科学家TOP1000榜单出炉&#xff0c;这份由Guide2Research发布的计算机科学家排名中&#xff0c;中国科学技术大学以16人入选力压清华、北大、浙大等计算机科学强校&#xff0c;高居全国第一&#xff01;中科大张亚勤等13位本科…

Linux可以对目录进行硬链接,Linux硬链接与软链接原理及用法解析

在linux系统中有种文件是链接文件&#xff0c;可以为解决文件的共享使用。链接的方式可以分为两种&#xff0c;一种是硬链接(hard link)&#xff0c;另一种是软链接或者也称为符号链接(symbolic link)。硬链接概念硬链接(hard link, 也称链接)就是一个文件的一个或多个文件名硬…

CentOS6实现路由器功能

网络之间的通信主要是依靠路由器&#xff0c;当然生成环境中是拥有路由器的&#xff0c;但是系统中的路由配置也是需要了解一下地&#xff0c;今天讲解一下在CentOS6环境下搭建路由器&#xff0c;此乃入门级的简单实验。拓扑如上图已经规划好&#xff0c;暂且使用静态路由演示。…

在近期,美众议院为何密集提出了15项新兴技术法案?

来源&#xff1a;资本实验室近期&#xff0c;美国众议院能源和商业委员会及消费者保护与商业小组委员会密集提出了15项与新兴技术相关的法案议程。这些法案开宗明义&#xff0c;建立了明确的目标&#xff1a;确保美国在新兴技术领域的领导地位&#xff0c;以在全球竞争力方面战…

javascript测试框架mocha

node测试框架mocha 简单、灵活、有趣&#xff0c;mocha是一个功能丰富的javascript测试框架&#xff0c;运行在node和浏览器中&#xff0c;使异步测试变得更加简单有趣。http://mochajs.org/ 安装 $ npm install --global mocha//全局安装$ npm install --save-dev mocha//项…

复杂指令集linux,精简指令集和复杂指令集区别

精简指令集概述精简指令集计算机(RISC:Reduced Instruction Set Computing RISC)是一种执行较少类型计算机指令的微处理器&#xff0c;起源于80年代的MIPS主机(即RISC机)&#xff0c;RISC机中采用的微处理器统称RISC处理器。这样一来&#xff0c;它能够以更快的速度执行操作(每…

求助马斯克实现载人飞行,NASA省了近300亿美元

出品 | 网易科技《知否》栏目组当美国宇航局&#xff08;NASA&#xff09;的宇航员于当地时间5月27日搭乘SpaceX的载人龙飞船升空时&#xff0c;他们将不仅仅是进入太空&#xff0c;还将开启一个可能具有变革意义的新时代&#xff0c;因为此前没有任何私人公司将人类送入轨道。…

Codeforces 138C(区间更新+离散化)

题意&#xff1a;有n棵树在水平线上&#xff0c;给出每棵树的坐标和高度&#xff0c;然后向左倒的概率和向右倒的概率&#xff0c;和为1&#xff0c;然后给出了m个蘑菇的位置&#xff0c;每一个蘑菇都有一个魔法值&#xff0c;假设蘑菇被压死了&#xff0c;也就是在某棵树[a[i]…

linux基础操作与实践,Linux操作系统基础与实践

《21世纪高等院校计算机网络工程专业规划教材:Linux操作系统基础与实践》由清华大学出版社出版。19.18定价&#xff1a;29.50(6.51折)/2014-06-01《Linux劋作系统基础与实践/21世纪高等院校计算机网络工程专业规划教材》内容共分10章&#xff0c;第1章主要讲解劋作系统概述、劋…

MIT机器学习种菜项目永久关停

来源&#xff1a;IEEE电气电子工程师Photo: Harry Goldstein麻省理工学院媒体实验室的开放农业计划&#xff08;Open Agriculture Initiative&#xff09;&#xff0c;由首席科学家Caleb Harper领导&#xff0c;于2020年4月30日被该大学永久关闭。媒体关系总监Kimberly Allen在…

FastLeaderElection

FastLeaderElection是zookeeper默认的选举算法,当peer处于ServerState.Looking状态时会执行FastLeaderElection.lookForLeader进行选主. 重要数据结构: 1.HashMap<Long, Vote> recvset: 本轮选举中来自 ServerState处于 Looking的 Peer的选票信息. 用于判断是否选举结束…

linux安装-bin.rpm,Linux离线安装jdk,bin、rpm和tar.gz三种方式及配置jdk环境变量

本文主要是为了记录安装过程&#xff0c;方便后续用到时可及时翻阅&#xff0c;如有不对之处&#xff0c;请各位不吝赐教。因离线安装方法较为常用&#xff0c;故本文主要说明使用离线方式安装jdk的方法&#xff0c;在线安装方法后续补充。第一步&#xff1a;下载jdk官网下载地…

万字总结,知识蒸馏如何在推荐系统中大显身手?

来源&#xff1a;AI科技评论作者 | 张俊杰编辑 | 丛 末本文首发于知乎 https://zhuanlan.zhihu.com/p/143155437随着深度学习的快速发展&#xff0c;优秀的模型层出不穷&#xff0c;比如图像领域的ResNet、自然语言处理领域的Bert&#xff0c;这些革命性的新技术使得应用效果快…

【模板】快速幂取模

快速幂取模的模板&#xff0c;要注意所有变量都要开成long long类型的防溢出&#xff1a; #include<cstdio> #include<algorithm> #include<cstring> typedef long long LL; const LL mod1e97; using namespace std; LL a,b; LL mi(LL x,LL y) {LL res1;whil…

linux vim debugger,Vim 调试:termdebug 入门

简介termdebug 是从 Vim 8.1 开始内置的调试插件&#xff0c;仅支持 GDB。本教程仅在 Linux 下(Ubuntu 16.04)测试通过。安装将 Vim 升级至 8.1 或以上版本。GDB 需升级至 7.12 或以上版本。启动默认情况下需手动加载 termdebug 插件&#xff1a;:packadd termdebug假设我们有一…

时空大数据可视化表达分析,看MapGIS七大“超能力”

文章转载自微信公众号中地数码MapGIS&#xff0c;版权归原作者及刊载媒体所有。伴随着人们探索空间的过程&#xff0c;信息的获取范围也从局部地面、全球地表、地球各个圈层扩展到地球内外的整个空间&#xff0c;从原有的二维平面空间基准逐步演变到三维空间基准&#xff0c;进…

map key char*

STL中map的key能否用char 呢&#xff1f;当然可以&#xff01; 在程序中需要用到一个map&#xff0c;本来是这样写的&#xff0c; map<string, int> mapStr; 为了追求效率&#xff0c;把string改成了char &#xff0c; map<char , int> mapStr; 结果呢&#xff1f;…

深扒ASML 的玩法,对工控企业生态圈的思考

来源&#xff1a;中国传动网自从美国的新一轮技术封锁发生后&#xff0c;普天之下的吃瓜群众为华为操碎了心&#xff0c;甚至卖菜的大妈偶尔讨论这件事。由此可见&#xff0c;半导体对国家科技、工业的影响有多大。半导体制造产业中&#xff0c;光刻机是核心设备&#xff0c;对…