1.创建一个工程,做一个表视图,并建一个自定义的Cell类

2.

//

//  MainTableViewController.h

//  QQ分组

//

//  Created by 黄权浩 on 14-10-26.

//  Copyright (c) 2014年 黄权浩. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface MainTableViewController : UITableViewController

{

@private

BOOL _isCell;//来区别是否点击了这个Cell

}

@end

//

//  MainTableViewController.m

//  QQ分组

//

//  Created by 黄权浩 on 14-10-26.

//  Copyright (c) 2014年 黄权浩. All rights reserved.

//

#import "MainTableViewController.h"

#import "MyCell.h"//自定义Cell

@interface MainTableViewController ()

@end

@implementation MainTableViewController

- (id)initWithStyle:(UITableViewStyle)style

{

self = [super initWithStyle:style];

if (self) {

// Custom initialization

}

return self;

}

- (void)viewDidLoad

{

[super viewDidLoad];

self.tableView.frame = CGRectMake(0, 60, 320, self.view.bounds.size.height-60);

self.tableView.separatorStyle=UITableViewCellSelectionStyleNone;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;//在这里返回你的分组数

}

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

{

NSLog(@"%ld",(long)section);

NSLog(@"_isCell:%d",_isCell);

switch (section) {

case 0:

if (_isCell) {

return 4;

}else {

return 1;

}

break;

default:

break;

}

return 0;

}

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

{

static NSString *cellIdentifier = @"mycell";

static NSString *cellIdentifier2 = @"mycell2";

NSLog(@"section:%ld",(long)indexPath.section);

NSLog(@"row:%ld",(long)indexPath.row);

MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];

switch ([indexPath section]) {

case 0:

switch ([indexPath row]) {

case 0:

if (cell == nil) {

cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

}

cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];

return cell;

break;

default:

if (cell2 == nil) {

cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2];

}

cell2.textLabel.text = @"12345";

return cell2;

break;

}

break;

default:

break;

}

return cell;

}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];

NSIndexPath *path0 = [NSIndexPath indexPathForRow:[indexPath row]+1 inSection:[indexPath section]];

NSIndexPath *path1 = [NSIndexPath indexPathForRow:[indexPath row]+2 inSection:[indexPath section]];

NSIndexPath *path2 = [NSIndexPath indexPathForRow:[indexPath row]+3 inSection:[indexPath section]];

NSArray *array = [NSArray arrayWithObjects:path0, path1, path2, nil];

switch ([indexPath section]) {

case 0:

switch ([indexPath row]) {

case 0:

if ([cell isOpen]) {

[cell setClosed];

_isCell = [cell isOpen];

[tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];

}else {

// 开启  isopen为yes

[cell setOpen];

// 将_boolSection1 设置为yes

_isCell = [cell isOpen];

[tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];

}

break;

default:

NSLog(@"default");

cell.textLabel.text = @"default";

break;

}

break;

default:

break;

}

}

//

//  MyCell.h

//  QQ分组

//

//  Created by 黄权浩 on 14-10-26.

//  Copyright (c) 2014年 黄权浩. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface MyCell : UITableViewCell

@property (nonatomic) BOOL isOpen;

- (void) setOpen;

- (void) setClosed;

@end

//

//  MyCell.m

//  QQ分组

//

//  Created by 黄权浩 on 14-10-26.

//  Copyright (c) 2014年 黄权浩. All rights reserved.

//

#import "MyCell.h"

@implementation MyCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 30)];

l.backgroundColor = [UIColor redColor];

l.tag = 101;

[self.contentView addSubview:l];

}

return self;

}

- (void) setOpen

{

[self setIsOpen:YES];

}

- (void) setClosed

{

[self setIsOpen:NO];

}

- (void)awakeFromNib

{

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end

3.实现效果

iOS Cell上实现简单的分组(类似与QQ分组)相关推荐

  1. Socket在iOS客户端上的简单实现 - 利用GCAsyncSocket框架

    Socket在iOS客户端上的简单实现 - 利用GCAsyncSocket框架 GCAsyncSocket 这是一个2003的开发出来的一个开源框架 首先把GCDAsyncSocket的.h和.m文件 ...

  2. html仿qq分组,iOS 实现类似QQ分组样式的两种方式

    思路 思路很简单,对模型数据操作或则控制界面显示 先看下json部分数据 "chapterDtoList": [{ "token": null, "i ...

  3. 【Android】史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。

    本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/53157090 本文出 ...

  4. iOS开发UI篇—简单介绍静态单元格的使用

    iOS开发UI篇-简单介绍静态单元格的使用 一.实现效果与说明 说明:观察上面的展示效果,可以发现整个界面是由一个tableview来展示的,上面的数据都是固定的,且几乎不会改变. 要完成上面的效果, ...

  5. 深度学习指南:在iOS平台上使用TensorFlow

    在利用深度学习网络进行预测性分析之前,我们首先需要对其加以训练.目前市面上存在着大量能够用于神经网络训练的工具,但TensorFlow无疑是其中极为重要的首选方案之一. 大家可以利用TensorFlo ...

  6. iOS知识分享 — iOS 13上的暗模式

    我们将本周的文章献给那些庆祝这个受人尊敬的假期的人,无论是同时还是在iOS 13进入通用汽车的过程中.我们希望一些快速提示可以帮助您避开即将到来的阴影. 暗模式是一种外观偏好,告诉系统和参与的应用程序 ...

  7. ios滚动条影响父页面 vue_在IOS系统上滚动条滚动到指定的位置出现空白页面的解决方案...

    在IOS系统上滚动条滚动到指定的位置出现空白页面的解决方案 原因: -webkit-overflow-scrolling:touch 解释: 由于使用-webkit-overflow-scrollin ...

  8. IOS 模仿qq分组那样展开与收起

    概述 模仿qq分组那样展开与收起的效果,相信大家在项目中总会碰到,今天给大家讲讲实现的思路. 不同的人有不同的实现方式,难易程度也会大不一样,我今天给大家讲的,算是一种比较简单快捷的实现方式. 内容 ...

  9. iOS流布局之UICollectionView简单应用

    iOS流布局UICollectionView系列一--初识与简单使用UICollectionView 一.简介 UICollectionView是iOS6之后引入的一个新的UI控件,它和UITable ...

最新文章

  1. Codeforces Gym 100513G G. FacePalm Accounting 暴力
  2. JS中怎样获取当前年以及前后几年并构造成对象数组
  3. 好久没有写什么东西了。。。。
  4. WinForm ListView
  5. valgrind 常见错误提示信息
  6. iTerm2 快捷键
  7. MySql DDL语言(数据库和数据表的管理)
  8. 解决VS中无法使用scanf的问题
  9. 交换机端口呈现err-disable的原因
  10. 个人项目总结----By Li Zhang
  11. 韩忠康 5天玩转mysql_玩转MySQL数据库5天就够了(2)
  12. Linux-2.6.32 NUMA架构之内存和调度
  13. 新版财经直播间系统 贵金属喊单直播间 视频直播室在线喊单 源码
  14. 长江大学计算机网络期末考试试题及答案,长江大学计算机基础考试试题
  15. UE4 蓝图教程(三) 材质
  16. vb.net多线程例子
  17. 自然生长不含咖啡碱的茶树新品种--T三有机可可茶
  18. 全差分运算放大器浅析
  19. Linux学习——废旧电脑再利用Ubuntu部署私有云Nextcloud
  20. 论文解读:6mA-Pred: identifying DNA N6-methyladenine sites based on deep learning

热门文章

  1. tp-wdr5620 创建虚拟服务器,TP-LINK路由器 TL-WDR5620 设置、使用、问题解答综合指南...
  2. 【客户机操作系统已禁用 CPU。请关闭或重置虚拟机】以及【该主机 CPU 类型不支持虚拟化性能计数器,模块“VPMC”启动失败,未能启动虚拟机】
  3. linux basename目录,Linux basename命令的使用方法
  4. Java中间件(1)--分布式系统中间件从入门到精通(五)
  5. 小蓝在一张无限大的特殊画布上作画。 这张画布可以看成一个方格图,每个格子可以用一个二维的整数坐标表示。 小蓝在画布上首先点了一下几个点:(0, 0), (2020, 11), (
  6. linux服务器只读,linux文件只读怎么修改_网站服务器运行维护
  7. 顶级动漫IP加持之下,3A策略游戏Mechaverse如何改变GameFi
  8. 想做盲盒扭蛋机小程序-如何选择服务商
  9. 【搜索小技巧】在Chrome浏览器直接进行百度、github等搜索
  10. 阿里云全球化云网络,保障北京冬奥全球“云转播”