前几天小伙伴要帮他做一个群聊功能,里面有好友列表,要求和微信的差不多(见下图),让小伙伴自己实现了下,他将CollectionView放在tableView的tableHead中,可是当添加好友或删除好友刷新数据源的时候并没有效果。让他将CollectionView放在tableView的cell中,结果是数据刷新了可是还是有问题删除后刷新数据时CollectionView的高度变的有问题,我就调了下,实现比较简单,只是一些细节问题,现在效果还蛮不错的,分享一下.

1.定义CollectionViewCell,并为删除按钮添加一个block

2.用TableView+CollectionView显示  此时注意:计算CollectionView的高度时,要注意行数是整数而且要有余进1

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "TKQunSheZhiCollectionViewCell.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    UITableView *_mTableView;
    CGFloat _imgHeight;
    UICollectionView *_mCollectionView;
    NSMutableArray *_mDataArray;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initTableView];
    _mDataArray = [NSMutableArray arrayWithObjects:", nil];
}

//----------TableView---
- (void)initTableView
{
    _mTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _mTableView.delegate = self;
    _mTableView.dataSource = self;
    [self.view addSubview:_mTableView];
}

//UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    ;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ) {
        static NSString *cellIdentifier = @"UITableViewCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }

        if (_mCollectionView) {
            [_mCollectionView removeFromSuperview];
        }
        [cell.contentView addSubview:[self createCollectionView]];

        return cell;
    }else{
        static NSString *cellStr = @"customCell";
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:nil options:nil] lastObject];
        }
        cell.nameLabel.text = @"AAA";

        return cell;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ) {
        )/ + ) * (()/) + ;
        return height;
    }else{
        ;
    }
}

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

    return 0.001;

}

//---------CollectionView----
- (UICollectionView *)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    _imgHeight = (self.view.frame.size.width - )/;
    layout.itemSize = CGSizeMake((self.view.frame.size.width - )/, _imgHeight + );
    layout.minimumLineSpacing = ;
    layout.minimumInteritemSpacing = ;
    layout.sectionInset = UIEdgeInsetsMake(, , , );

    _mCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(, , self.view.frame.size.width, ((_imgHeight + ) * (()/)) + ) collectionViewLayout:layout];

    _mCollectionView.delegate = self;
    _mCollectionView.dataSource = self;
    _mCollectionView.backgroundColor = [UIColor whiteColor];
    _mCollectionView.scrollEnabled = NO;

    [_mCollectionView registerNib:[UINib nibWithNibName:@"TKQunSheZhiCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"TKQunSheZhiCollectionViewCell"];
    return _mCollectionView;
}

//UICollectionViewDataSource,UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    ;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    ;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",indexPath);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TKQunSheZhiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TKQunSheZhiCollectionViewCell" forIndexPath:indexPath];

    ) {
        cell.mNickName.hidden = YES;
        cell.mDelBtn.hidden = YES;
        ) {
            cell.mHeadImg.image = [UIImage imageNamed:@"qunzu-jiahao"];
        }
        ){
            cell.mHeadImg.image = [UIImage imageNamed:@"qunzu-jianhao"];
        }
    }else{

        cell.delMemberBlock = ^()
        {
            [_mDataArray removeLastObject];
            [_mTableView reloadData];

        };
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

3.效果图

IOS仿微信朋友圈好友展示的更多相关文章

  1. iOS - 仿微信朋友圈视频剪切功能

    分析需求 我们先看一看微信的界面 微信效果图 1.页面下部拖动左边和右边的白色竖条控制剪切视频的开始和结束时间,预览界面跟随拖动位置跳到视频相应帧画面,控制视频长度最长15秒,最短5秒 2.拖动下部图 ...

  2. Android NineGridLayout — 仿微信朋友圈和QQ空间的九宫格图片展示自定义控件

    NineGridLayout 一个仿微信朋友圈和QQ空间的九宫格图片展示自定义控件. GitHub:https://github.com/HMY314/NineGridLayout 一.介绍 1.当只 ...

  3. iOS版微信朋友圈数据库的简要分析

    本文版权归cxun所有,如有转载请注明出处与本文链接,谢谢!原文地址:http://www.cnblogs.com/cxun/p/4550523.html 之前写了一些关于微信聊天记录的博文之后,不少 ...

  4. Android 仿微信朋友圈添加图片

    github地址(欢迎下载Demo) https://github.com/zhouxu88/WXCircleAddPic 老习惯,先上图,着急用的朋友,直接带走Demo,先拿来用吧,毕竟老板催的紧, ...

  5. Py:数据挖掘之对个人微信朋友圈好友的性别、区域、昵称、签名信息进行情感分析——Jason niu

    #Py:数据挖掘之对微信朋友圈好友的性别.区域.昵称.签名信息进行情感分析——Jason niu import os import re import csv import time import j ...

  6. Android 仿微信朋友圈发动态功能(相册图片多选)

    代码分享 代码名称: 仿微信朋友圈发动态功能(相册图片多选) 代码描述: 仿微信朋友圈发动态功能(相册图片多选) 代码托管地址: http://www.apkbus.com/android-15276 ...

  7. Android 高仿微信朋友圈动态, 支持双击手势放大并滑动查看图片。

    转载请注明出处:http://blog.csdn.net/sk719887916/article/details/40348873 作者skay: 最近参与了开发一款旅行APP,其中包含实时聊天和动态 ...

  8. React Native(九)——实现仿微信朋友圈发表动态功能

    好像很久都没写博客了,罪过罪过~ 许是因为刚接触App有点生疏不得窍门吧,这个月还没有更新过文章.小个把月下来,还是觉得应该边学边总结,这样才能像大神靠近(最近刚接触同业的大牛级人物,还是从中学到了很 ...

  9. Android仿微信朋友圈,全文收起功能,附源码

    在众多的社交类软件中,朋友圈是必不可少的,可以与好友.同学等分享自己的日常和有意思的事情,在开发社交类App时,朋友圈发表的内容你不可能让他全部显示,全部显示的话用户体验度会非常不好,这时就要用到全文 ...

随机推荐

  1. .NET控件名称缩写一览表

    转载自如下链接: https://www.cnblogs.com/xpvincent/p/9334851.html 字体实在是太小了,我看着好闹心,就复制过来自己放大下,谢谢. 标准控件1 btn B ...

  2. Kafka与.net core(三)kafka操作

    1.Kafka相关知识 Broker:即Kafka的服务器,用户存储消息,Kafa集群中的一台或多台服务器统称为broker. Message消息:是通信的基本单位,每个 producer 可以向一个 ...

  3. 如何成功导入SlidingMenu库?

    SlidingMenu是一个开源的侧滑菜单(https://github.com/jfeinstein10/SlidingMenu).  为大家的安卓程序提供侧滑菜单,这个功能也非常有用. 要想正常使 ...

  4. CF79D Password

    题目链接 题意:给定长度为n的0/1序列,初始值都为0.你每次可以在给定的l个长度中的\(a_i\)并将序列中长度为\(a_i\)的部分取反.使得最终状态为\(x_1\)~\(x_k\),求最少取反次 ...

  5. 百度地图API鼠标获取坐标

    var map = new BMap.Map('map'); var poi = new BMap.Point(112.53, 37.87); map.enableScrollWheelZoom(); ...

  6. 八.linux系统文件属性知识

    1.文件属性权限是12位,现在只看9位,其中每3个一组,为:属主权限.属组权限.其他权限,其中r可读,w可写,x可执行,如图: 2.文件属性之软硬链接   linux系统中有两种链接,为硬链接(ln) ...

  7. JSONP前世今生及原理

    https://blog.csdn.net/hansexploration/article/details/80314948 http://www.cnblogs.com/yuzhongwusan/a ...

  8. 使用X-Pack插件来进行权限控制

    1.为elasticsearch安装X-Pack插件.进入 elasticsearch根目录,执行: bin/elasticsearch-plugin install x-pack杀掉进程,重启es, ...

  9. java后台简单从阿里云上传下载文件并通知前端以附件的形式保存

    一. 首先开通阿里的OSS 服务 创建一个存储空间在新建一个Bucket 在你新建的bucket有所需的id和key 获取外网访问地址或者是内网 看个人需求 我使用的是外网(内网没用过 估计是部署到阿 ...

  10. package.json和bower的参数解释

    package.json和bower的参数解释   一.package.json解释: package.json是用来声明项目中使用的模块,这样新的环境部署时,只要在package.json文件所在的 ...