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




//
// FriendGroup.h
// FriendsList
//
// Created by hellovoidworld on 14/12/12.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h> @class Friend; @interface FriendGroup : NSObject /** 好友组 */
@property(nonatomic, strong) NSArray *friends; /** 好友组名 */
@property(nonatomic, copy) NSString *name; /** 在线人数 */
@property(nonatomic, assign) int online; - (instancetype) initWithDictionary:(NSDictionary *) dictionary;
+ (instancetype) friendGroupWithDictionary:(NSDictionary *) dictionary; @end

/** 加载数据 */
- (void)setFriendGroup:(FriendGroup *)friendGroup
/** 子控件布局方法
在init的时候,只分配的内存,没有初始化控件的尺寸,在此处header已经有了位置尺寸了
*/
- (void)layoutSubviews {
// 必须先调用父类的方法
[super layoutSubviews]; // 1.背景
self.headerButtonView.frame = self.bounds; // 2.在线人数/组内总人数
CGFloat countWidth = ;
CGFloat countHeight = self.frame.size.height;
CGFloat countX = self.frame.size.width - - countWidth;
CGFloat countY = ;
self.onlineCountView.frame = CGRectMake(countX, countY, countWidth, countHeight);
}
/** 自定义每个section的头部 */
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
FriendHeader *header = [FriendHeader friendHeaderWithTableView:self.tableView];
header.friendGroup = self.friendGroups[section];
return header;
}

/** 自定义构造方法 */
+ (instancetype) cellWithTableView:(UITableView *) tableView {
static NSString *ID = @"friendCell";
FriendCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (nil == cell) {
cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
} return cell;
} /** 加载数据 */
- (void)setFriendData:(Friend *)friendData {
_friendData = friendData; self.imageView.image = [UIImage imageNamed:friendData.icon];
self.textLabel.text = friendData.name;
self.textLabel.textColor = friendData.isVip?[UIColor redColor]:[UIColor blackColor];
self.detailTextLabel.text = friendData.intro;
}

/** 是否伸展显示好友 */
@property(nonatomic, assign, getter=isOpened) BOOL opened;
// 1.4点击事件
[headerButtonView addTarget:self action:@selector(headerClicked) forControlEvents:UIControlEventTouchUpInside];
/** 点击事件 */
- (void) headerClicked {
// 1.伸展、隐藏组内好友
self.friendGroup.opened = !self.friendGroup.isOpened; // 2.刷新tableView
if ([self.delegate respondsToSelector:@selector(friendHeaderDidClickedHeader:)]) {
[self.delegate friendHeaderDidClickedHeader:self];
}
}
@protocol FriendHeaderDelegate <NSObject>
/** header被点击的代理方法 */
@optional
- (void) friendHeaderDidClickedHeader:(FriendHeader *) header; @end
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
FriendGroup *group = self.friendGroups[section];
// 先检查模型数据内的伸展标识
return group.isOpened? group.friends.count : ;
}
#pragma mark - FriendHeaderDelegate方法
- (void)friendHeaderDidClickedHeader:(FriendHeader *)header {
// 刷新数据
[self.tableView reloadData];
}

/**
被加到父控件之前
由于tableView刷新数据后,所有header会被重新创建,所以要在这里对箭头朝向做出修改
*/
- (void)didMoveToSuperview {
// 改变箭头朝向,顺时针旋转90度
CGFloat rotation = self.friendGroup.isOpened? M_PI_2 : ;
self.headerButtonView.imageView.transform = CGAffineTransformMakeRotation(rotation);
}
// 改变箭头填充方式为居中
[headerButtonView.imageView setContentMode:UIViewContentModeCenter];
// 不需要裁剪箭头图片的边界
[headerButtonView.imageView setClipsToBounds:NO];

[iOS基础控件 - 6.9.3] QQ好友列表Demo TableView的更多相关文章
- [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
A.需求 1.类似QQ.微信顶部或者底部的窗口转换导航条 2.给每个页面添加相应内容 B.UITabBarController 1.基本概念: (1)内容高度 iOS7之前内容高度为:屏幕高度 - ...
- [iOS基础控件 - 4.4] 进一步封装"APP列表”,初见MVC模式
A.从ViewController分离View 之前的代码中,View的数据加载逻辑放在了总的ViewController中,增加了耦合性,应该对控制器ViewController隐藏数据加载到Vie ...
- [iOS基础控件 - 6.10.1] PickerView 餐点搭配Demo
A.需求 1.使用PickerView做出有3列餐点(水果.主菜.饮料)的搭配Demo 2.选择的餐点实时显示在“显示区” 3.提供“随机”按钮,随机选择菜品搭配 B.实现步骤 1.拖入一个Pic ...
- [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)
A.概述 在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能 1.按钮点击后,显示为“已下载”,并且不 ...
- [iOS基础控件 - 3.1] QQ登陆界面
A.storyboard 控件版 1.label 2.textfield a.Keyboard Type 账号:Number Pad 密码:Num ...
- iOS 基础控件(下)
上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...
- [iOS基础控件 - 6.9] 聊天界面Demo
A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...
- [iOS基础控件 - 7.0] UIWebView
A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的 2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...
- [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储
A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改) 这个代码 ...
随机推荐
- JAVA中获取工程路径的方法
在jsp和class文件中调用的相对路径不同.在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProp ...
- mssql修改链接数为默认值
EXEC sys.sp_configure N'show advanced options', N'1' RECONFIGURE WITH OVERRIDE GO EXEC sys.sp_confi ...
- UVa 10285 Longest Run on a Snowboard【记忆化搜索】
题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <c ...
- Android listView如何判断数据多屏显示 (2012-03-06 09:47:04)
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int tot ...
- android开发中eclipse里xml开发的自动提示和使用帮助快捷键提示
Eclipse Android 代码自动提示功能 Eclipse for android 设置代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > ...
- 编译pure-ftpd时提示错误Your MySQL client libraries aren't properly installed
如果出现类似configure: error: Your MySQL client libraries aren’t properly installed 的错误,请将mysql目录下的 includ ...
- ActionBarSherlock的学习笔记(四) ------------ ActionBarSherlock中的搜索及SearchView的使用
在使用ActionBarSherlock定义app的头部操作时,会经常看见搜索的动作,本文主要介绍一下搜索是如何实现的. 1. SearchView 是搜索的核心组件,具体介绍请参考Android官方 ...
- 一天一个Java基础——对象和类
1.在Java中你所做的全部工作就是定义类,产生那些类的对象,以及发送消息给这些对象 2.可以在类中设置两种类型的元素:字段(也被称作数据成员)和方法(也被称作成员函数) 3.字段可以是任何类型的对象 ...
- java 访问器方法中对象引用的问题
"注意不要编写返回引用可变对象的访问器方法".因为会破坏类的封装性,引用的内容可能会被改变,产生业务逻辑上的错误. 什么是可变对象? 先要搞清楚java中值传递和引用传递的问题,总结如下: 1.对象就 ...
- AFNetworking速成教程
转:http://palmsky.net/?p=4138 本文是由 iOS Tutorial 小组成员 Scott Sherwood撰写,他是一个基于位置动态加载(Dynamically Loaded ...