ios QQ下拉列表 UITableViewHeaderFooterView

QQ下拉列表,最近找了一下网上没有类似的例子,今天做了一个Demo

图片可以在评论里留言留下邮箱,

#import "ViewController.h"

@interface
ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSMutableArray * dataArray;

@property (nonatomic,weak)UITableView * tabelView;

@property (nonatomic,strong)NSMutableDictionary * imageDict;// 分组对应下拉箭头图片字典

@property (nonatomic,strong)NSMutableDictionary * stateDict;// 分组对应状态字典

@end

@implementation ViewController

- (void)viewDidLoad {

[super
viewDidLoad];

// 加载数据

[self
_loadData];

//
加载视图

[self
_loadView];

}

#pragma mark -_loadData

- (void)_loadData{

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

self.dataArray = [NSMutableArray
arrayWithContentsOfFile:path];

}

/**

*  懒加载

*

*  @return <#return value description#>

*/

- (NSMutableDictionary *)imageDict{

if (_imageDict ==
nil) {

_imageDict = [NSMutableDictionary
dictionary];

}

return
_imageDict;

}

- (NSMutableDictionary *)stateDict{

if (_stateDict ==
nil) {

_stateDict = [NSMutableDictionary
dictionary];

}

return
_stateDict;

}

#pragma mark -_loadView

- (void)_loadView{

UITableView * tableView = [[UITableView
alloc]initWithFrame:self.view.frame
style:UITableViewStyleGrouped];

tableView.delegate =
self;

tableView.dataSource =
self;

//设置分组头部和尾部的高度

tableView.sectionFooterHeight =
2;

tableView.sectionHeaderHeight =
40;

tableView.rowHeight =
60;

self.tabelView = tableView;

[self.view
addSubview:tableView];

}

#pragma mark - UITableViewDataSource

#pragma mark - 分组头部高度//
不加第一组头显示不出来

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

return 40;

}

#pragma mark - 返回分组数量

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return
self.dataArray.count;

}

#pragma mark - 设置分组标题

//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

//   id temp = self.dataArray[section];

//

//    return temp[@"group"];

//}

#pragma mark - 自定义头部视图

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

static NSString * identy =
@"headView";

// 类似cell的重利用机制

UITableViewHeaderFooterView * hfVeiw = [tableView
dequeueReusableHeaderFooterViewWithIdentifier:identy];

if (!hfVeiw) {

hfVeiw = [[UITableViewHeaderFooterView
alloc]initWithReuseIdentifier:identy];

hfVeiw.contentView.backgroundColor = [UIColor
grayColor];

// 初始化button

UIButton * button = [UIButton
buttonWithType:UIButtonTypeCustom];

button.frame =
CGRectMake(0,
0, self.view.frame.size.width,
40);

[hfVeiw.contentView
addSubview:button];

// 初始化imageView

UIImageView * imageView = [[UIImageView
alloc]initWithFrame:CGRectMake(5,
12, 20,
20)];

UIImage * image = [UIImage
imageNamed:@"disclosure.png"];

imageView.image = image;

imageView.tag =
1001;

[button
addSubview:imageView];

// button添加点击事件

[button addTarget:self
action:@selector(clickAction:)
forControlEvents:UIControlEventTouchUpInside];

}

id temp = self.dataArray[section];

//
拿出button重新设置标题

UIButton * button = [hfVeiw.contentView.subviews
firstObject];

[button setTitle:temp[@"group"]
forState:UIControlStateNormal];

UIImageView * imageView = (UIImageView *)[button
viewWithTag:1001];

//
通过tag值获取点击的是哪个组

button.tag = section;//控件默认的tag都为0,获取未设置tag的控件,会崩,但是设置某控件tag为0则不会

//
将最新的ImageView加入到字典

[self.imageDict
setObject:imageView
forKey:@(section)];

UIImageView * targetImageView = (UIImageView *)self.imageDict[@(section)];

// 为何出现此BUG,如何防止:1.下拉的时候出现重复利用,所以在重复利用后获取从池子取出的imageView,根据当前状态(打开、关闭)设置图片状态,2.点击section展开或者收缩列表,也要从字典获取imageView,并根据当前的状态获取

// 此处解决imageView重复利用的BUG问题 给从池子里取出的imageView根据状态,对其状态条件取反(即当前关闭取反石达开,因为点击之后状态要改变)重新设置图片形状,然后添加动画效果才有动画效果(如果不重新设置图片状态没有动画效果)

if (self.stateDict[@(section)]) {// 如果section组是打开的让从池子随即取出的图片顺时针旋转(图像本身)90°

targetImageView.transform =
CGAffineTransformMakeRotation(M_PI_2);

}else{

targetImageView.transform =
CGAffineTransformIdentity;// 如果section组是关闭的是使图片置为原始图片状态

}

return hfVeiw;

}

#pragma mark - clickAction:

- (void)clickAction:(UIButton *)button{

NSInteger section = button.tag;

BOOL isOpen = (self.stateDict[@(section)] ==
nil);//isOpen default is NO

if (isOpen) {

[self.stateDict
setObject:@(1)
forKey:@(section)];

}else{

[self.stateDict
removeObjectForKey:@(section)];

}

NSLog(@"----------%li,%@,%i",section,self.stateDict[@(section)],isOpen);

NSIndexSet * set = [NSIndexSet
indexSetWithIndex:section];

[self.tabelView
reloadSections:set withRowAnimation:UITableViewRowAnimationFade];//

//
设置动画

//
通过字典获取对应的imageView

UIImageView * imageView =
self.imageDict[@(section)];

if (!isOpen) {// 如果下拉列表是关闭的,就打开它(图片顺时针旋转90)

imageView.transform =
CGAffineTransformMakeRotation(M_PI_2);

}else{// 如果下拉列表是打开的,就关闭它(图片置为原始状态)

imageView.transform =
CGAffineTransformIdentity;//
恢复到原始状态

}// 以上if解决图片没有动画效果

[UIView
animateWithDuration:0.3
animations:^{

//
重新判断状态

if (isOpen) {

imageView.transform =
CGAffineTransformMakeRotation(M_PI_2);

}else{

imageView.transform =
CGAffineTransformIdentity;

}

}];

}

#pragma mark - 返回每组的行数

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

id temp = self.dataArray[section];

NSArray * array = [temp
objectForKey:@"friends"];

if (self.stateDict[@(section)]!=nil) {

return array.count;

}

NSLog(@"************%@",self.stateDict[@(section)]);

return 0;

}

#pragma mark - cell

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

static NSString * identy =
@"myTable";

UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:identy];

if (cell == nil) {

cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identy];//UITableViewCellStyleSubtitle(选择有副标题的,以添加副标题)

}

//
增加标题

id temp = self.dataArray[indexPath.section];

NSArray * section = [temp
objectForKey:@"friends"];

cell.textLabel.text = section[indexPath.row];

//
增加头像

NSString * imageName = [NSString
stringWithFormat:@"head%d",arc4random_uniform(7)+1];

cell.imageView.image = [UIImage
imageNamed:imageName];

//
增加子标题

cell.detailTextLabel.text =
@"在线";

return cell;

}

@end

ios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios QQ下拉列表 UITableViewHeaderFooterViewios
QQ下拉列表 UITableViewHeaderFooterView

时间: 2024-08-05 08:00:35

ios QQ下拉列表 UITableViewHeaderFooterView的相关文章

ios UItableView,UITableViewHeaderFooterView分组头部的重用机制,简单地仿射变换CGAffineTransform

怎样设置包括第一栏在内相同高度的section(小技巧,虽然容易但容易忽略) *第一步,在viewdidload里将尾部设为0,table.sectionFooterHeight = 0;(代理方法)- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0; }虽然也可以设置尾部高度,但是设置后没有效果 第二步,调用tableView的代理方法- (CGF

iOS QQ第三方登实现

我们经常会见到应用登陆的时候会有QQ,微信,微博等的第三方登陆 如图: 下面我们主要讲一下qq的第三方登陆如何实现 首先,到官网注册: http://wiki.connect.qq.com 一,下载SDK 下载SDK  地址: http://wiki.open.qq.com/wiki/mobile/SDK下载 下载最新版本的iOS_SDK_V2.9 二,SDK的目录结构 下载的文件结构如下 sample:示例代码 1. TencentOpenAPI.framework打包了iOS SDK的头文件

iOS QQ登录 傻瓜式集成

一,iOS SDK 下载 请到SDK下载页面下载最新版本QQ登录iOS SDK. 二,iOS SDK目录结构 iOS SDK包中带有两个文件: 1. TencentOpenAPI.framework打包了iOS SDK的头文件定义和具体实现. 2. TencentOpenApi_iOS_Bundle.bundle 打包了iOS SDK需要的资源文件. 三,将iOS SDK文件添加到工程中 1. 将iOS SDK中的TencentOpenAPI.framework和TencentOpenApi_I

iOS QQ分享图片无反应问题

受iOS 9 上 http 限制 需要在info.plist文件添加必要string <key>LSApplicationQueriesSchemes</key> <array> <string>mqqopensdkapiv2</string> <string>mqqopensdkapiv3</string> <string>wtloginmqq2</string> <string>we

iOS QQ列表效果实现

效果如下: 实现效果主要分为两个部分: 数据模型 tableview 要实现tableview需要实现DataSource和delegate datasource主要作用在于显示什么数据 delegate主要作用是事件响应即处理 代码如下:.h // controller @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, 

PopupWindow实现仿iOS QQ音乐上拉菜单栏(支持手势以及点击操作)

转载请注明出处:王亟亟的大牛之路 能力OK的小伙伴可以不看N2,源码在最下面 今天早上一个Andorid群的小伙伴问了我一些PopupWindow的问题,正好昨天晚上我注意到QQ音乐的一个菜单栏,那么今天就按照那个实现做一下(UI瞎凑合的你懂的) 先上下原图: 再贴一下我们的效果(除了长得不像也没什么,哈哈哈): 功能实现: 1:底部PopupWindow呈现 2:手势动作操作控件 3:按钮操作控件 4:控件内部的点击事件 How to do? 分析: 首先这是一个标准的底部的PopupWind

用友盟做的iOS qq三方登录 问题求解决

//QQ登录 - (void)qqBtnClick:(UIButton *)btn { NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeMobileQQ]: UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ]; sns

iOS QQ第三方登录

http://www.jianshu.com/p/ab3c1b177841 http://blog.csdn.net/zhonggaorong/article/details/51699623 http://blog.csdn.net/jackren_developer/article/details/52065587

QQ聊天原理初识

1:qq之间文件的传输是通过p2p通信进行的. 2:qq之间的表情发送实际上就是文字的发送,是client再接受到文字之后在本地自己进行转换 3:qq之间的通信既能够通过udp也能够通过Tcp 尽管udp数据传输的时候数据可能会丢失,可是腾讯公司做了对应的操作,保证的数据传输的稳定性.主要用udp是由于udp传输效率高. 同一时候qq发送消息不是点对点的是client-server-client.由于qq须要查询消息记录. 4:两个局域网之间的p2p通信是有一定难度的 iOS QQ推送聊天原理