热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

TableView下拉cell

效果如下:源码如下:12MainViewController.m3NodeTableView45CreatedbyChenJungangon141110.6Copyright(c)


效果如下:
,

源码如下:

,,
  1 //
  2 //  MainViewController.m
  3 //  NodeTableView
  4 //
  5 //  Created by ChenJungang on 14/11/10.
  6 //  Copyright (c) 2014年 ChenJungang. All rights reserved.
  7 //
  8 
  9 #import "MainViewController.h"
 10 #import "MainCell.h"
 11 
 12 #define MAX_Count 55535
 13 
 14 
 15 @interface MainViewController ()
 16 
 17 @property (strong, nonatomic) UITableView   *tableView;
 18 @property (strong, nonatomic) NSArray       *dataArray;
 19 @property (assign, nonatomic) NSInteger     rowCount;
 20 @property (assign, nonatomic) NSInteger     sectionCount;
 21 
 22 @end
 23 
 24 @implementation MainViewController
 25 
 26 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
 27     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 28     if (self) {
 29         // Custom initialization
 30         self.rowCount = 0;
 31         self.sectiOnCount= MAX_Count;
 32     }
 33     return self;
 34 }
 35 
 36 - (void)viewDidLoad {
 37     [super viewDidLoad];
 38     self.title = @"node tableView";
 39     [self.view addSubview:self.tableView];
 40 }
 41 -(NSArray*)dataArray {
 42     if (!_dataArray) {
 43         self.dataArray = @[@{@"array": @[@{@"name":@"11", @"position":@"position1"},
 44                                          @{@"name":@"12", @"position":@"position2"},
 45                                          @{@"name":@"13", @"position":@"position3"},
 46                                          @{@"name":@"14", @"position":@"position4"},
 47                                          @{@"name":@"15", @"position":@"position5"}],@"name":@"one", @"position":@"position—one"},
 48                            @{@"array": @[@{@"name":@"21", @"position":@"position1"},
 49                                          @{@"name":@"22", @"position":@"position2"},
 50                                          @{@"name":@"23", @"position":@"position3"},
 51                                          @{@"name":@"24", @"position":@"position4"},
 52                                          @{@"name":@"25", @"position":@"position5"}],@"name":@"two", @"position":@"position—two"},
 53                            @{@"array": @[@{@"name":@"31", @"position":@"position1"},
 54                                          @{@"name":@"32", @"position":@"position2"},
 55                                          @{@"name":@"33", @"position":@"position3"},
 56                                          @{@"name":@"34", @"position":@"position4"},
 57                                          @{@"name":@"35", @"position":@"position5"}],@"name":@"three", @"position":@"position—three"},
 58                            @{@"array": @[@{@"name":@"41", @"position":@"position1"},
 59                                          @{@"name":@"42", @"position":@"position2"},
 60                                          @{@"name":@"43", @"position":@"position3"},
 61                                          @{@"name":@"44", @"position":@"position4"},
 62                                          @{@"name":@"45", @"position":@"position5"}],@"name":@"four", @"position":@"position—four"},
 63                            @{@"array": @[@{@"name":@"51", @"position":@"position1"},
 64                                          @{@"name":@"52", @"position":@"position2"},
 65                                          @{@"name":@"53", @"position":@"position3"},
 66                                          @{@"name":@"54", @"position":@"position4"},
 67                                          @{@"name":@"55", @"position":@"position5"}],@"name":@"five", @"position":@"position—five"}];
 68     }
 69     return _dataArray;
 70 }
 71 - (UITableView *)tableView{
 72     if (!_tableView) {
 73         CGRect rect = self.view.bounds;
 74         rect.origin.y = 0;
 75         rect.size.height = rect.size.height - rect.origin.y;
 76         _tableView = [[UITableView alloc]initWithFrame:rect style:UITableViewStylePlain];
 77         _tableView.delegate = self;
 78         _tableView.dataSource = self;
 79         _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
 80     }
 81     return _tableView;
 82 }
 83 
 84 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
 85     return self.dataArray.count;
 86 }
 87 
 88 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 89     if (_sectionCount != MAX_Count) {
 90         if (section == _sectionCount) {
 91             return 1 + _rowCount;
 92         }
 93         return 1;
 94     }else{
 95         return 1;
 96     }
 97 }
 98 
 99 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
100     static NSString *CellId = @"CellId";
101     MainCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
102     if (!cell) {
103         cell = [MainCell loadFromXib];
104     }
105     if (indexPath.row == 0) {
106         cell.nameLabel.text = self.dataArray[indexPath.section][@"name"];
107         cell.positionLabel.text = self.dataArray[indexPath.section][@"position"];
108     }else{
109         cell.nameLabel.text = self.dataArray[indexPath.section][@"array"][indexPath.row-1][@"name"];
110         cell.positionLabel.text = self.dataArray[indexPath.section][@"array"][indexPath.row-1][@"position"];
111     }
112     return cell;
113 }
114 
115 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
116 {
117     [tableView beginUpdates];
118     [tableView deselectRowAtIndexPath:indexPath animated:YES];
119     NSUInteger number =[self.dataArray[indexPath.section][@"array"]  count];
120     if (indexPath.row == 0) {
121         if(_sectiOnCount== MAX_Count){
122             _sectiOnCount= indexPath.section;
123             [self addCellwithNumber:number];
124         }else if (_sectiOnCount== indexPath.section) {
125             [self removeCellwithNumber:number];
126             _sectiOnCount= MAX_Count;
127         }else{
128             [self removeCellwithNumber:number];
129             _sectiOnCount= indexPath.section;
130             [self addCellwithNumber:number];
131         }
132     }
133     [tableView endUpdates];
134 }
135 
136 -(void)removeCellwithNumber:(NSInteger)number
137 {
138     for (int i=(int)number; i>=1; i--) {
139         --_rowCount;
140         [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:i inSection:_sectionCount]]
141                               withRowAnimation:UITableViewRowAnimationTop];
142     }
143     
144 }
145 -(void)addCellwithNumber:(NSInteger)number
146 {
147     for (int i=1; i<=number; i++) {
148         ++_rowCount;
149         [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:i inSection:_sectionCount]]
150                               withRowAnimation:UITableViewRowAnimationTop];
151     }
152 }
153 
154 - (void)didReceiveMemoryWarning {
155     [super didReceiveMemoryWarning];
156     // Dispose of any resources that can be recreated.
157 }
158 
159 @end
View Code

核心代码:

,

TableView下拉cell


推荐阅读
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了Java高并发程序设计中线程安全的概念与synchronized关键字的使用。通过一个计数器的例子,演示了多线程同时对变量进行累加操作时可能出现的问题。最终值会小于预期的原因是因为两个线程同时对变量进行写入时,其中一个线程的结果会覆盖另一个线程的结果。为了解决这个问题,可以使用synchronized关键字来保证线程安全。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • 十大经典排序算法动图演示+Python实现
    本文介绍了十大经典排序算法的原理、演示和Python实现。排序算法分为内部排序和外部排序,常见的内部排序算法有插入排序、希尔排序、选择排序、冒泡排序、归并排序、快速排序、堆排序、基数排序等。文章还解释了时间复杂度和稳定性的概念,并提供了相关的名词解释。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
author-avatar
TheKing小狼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有