当前位置: 首页 > news >正文

注册网站要多少钱网站建设开发外包公司

注册网站要多少钱,网站建设开发外包公司,有哪些在线做图的网站,广东网站建设电话咨询文章目录 前言一、实现效果二、折叠cell的实现原理三、实现折叠cell的高度变化四、实现选中点击的单元格总结 前言 在暑假的3GShare中用到了折叠cell控件,特此总结博客记录 一、实现效果 二、折叠cell的实现原理 首先我们需要知道ScrollView的是TableView的父类&a…

文章目录

  • 前言
  • 一、实现效果
  • 二、折叠cell的实现原理
  • 三、实现折叠cell的高度变化
  • 四、实现选中点击的单元格
  • 总结


前言

在暑假的3GShare中用到了折叠cell控件,特此总结博客记录


一、实现效果

在这里插入图片描述

二、折叠cell的实现原理

首先我们需要知道ScrollView的是TableView的父类,我们可以通过代码来控制我们需要展示的cell的行数 ,也就是tableview的高度。
我们可以通过按钮来实现tableview的展开与关闭,并且通过- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法来实现我们单元格的切换

三、实现折叠cell的高度变化

既然我们已经知道实现折叠cell的关键是通过按钮控制tableview的高度,那么我们现在给出按钮点击函数

- (void)pressUp:(UIButton *)btn {if (btn.tag == 1002) {[btn setImage:[UIImage imageNamed:@"shou.png"] forState:UIControlStateNormal];_tableView.frame = CGRectMake(270, 200, 95, 20);btn.tag--;} else {[btn setImage:[UIImage imageNamed:@"fang.png"] forState:UIControlStateNormal];_tableView.frame = CGRectMake(270, 200, 95, 80);btn.tag++;}
}

如此一来便实现了我们点击按钮时我们展示的tableview高度会随按钮的点击而变化

四、实现选中点击的单元格

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {// 从_dataArray获取被选中的项目NSString *selectedItem = _dataArray[indexPath.section];// 从_dataArray中移除被选中的项目[_dataArray removeObjectAtIndex:indexPath.section];// 将被选中的项目插入到_dataArray的开头[_dataArray insertObject:selectedItem atIndex:0];// 重新加载整个UITableView的数据[_tableView reloadData];// 调用pressUp:方法,执行按钮状态的切换[self pressUp:_zhedie];
}

当选择(点击)一个单元格时,将所对应部分的数据从_dataArray中移动到数组的顶部。这在didSelectRowAtIndexPath方法中完成。然后重新加载UITableView,并调用pressUp:方法以确保正确的布局。

总结

如此一来我们便简单实现了我们的折叠cell
以下给出完整的简单折叠cell的实现代码

- (void)viewDidLoad {[super viewDidLoad];//折叠cell=======_tableView = [[UITableView alloc] initWithFrame:CGRectMake(270, 200, 95, 80) style:UITableViewStylePlain];_tableView.delegate = self;_tableView.dataSource = self;_dataArray = [NSMutableArray arrayWithObjects:@"cell1", @"cell2", @"cell3", @"cell4", nil];[self.view addSubview:_tableView];_zhedie = [UIButton buttonWithType:UIButtonTypeSystem];_zhedie.frame = CGRectMake(270 + 95, 200, 20, 20);_zhedie.backgroundColor = [UIColor whiteColor];[_zhedie setImage:[UIImage imageNamed:@"shou.png"] forState:UIControlStateNormal];[_zhedie addTarget:self action:@selector(pressUp:)forControlEvents:UIControlEventTouchUpInside];_zhedie.tag = 1001;[self.view addSubview:_zhedie];if (_zhedie.tag == 1001) {_tableView.frame = CGRectMake(270, 200, 95, 20);}//=======折叠cell}}//====折叠cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return 1;
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 4;
}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {return 20;
}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {NSString *selectedItem = _dataArray[indexPath.section];[_dataArray removeObjectAtIndex:indexPath.section];[_dataArray insertObject:selectedItem atIndex:0];[_tableView reloadData];[self pressUp:_zhedie];
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {NSString *strID = @"ID";//尝试获取可以复用的单元格//如果得不到,返回为nilUITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:strID];if (cell == nil) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID];}//单元格文字赋值cell.textLabel.text = [_dataArray objectAtIndex:indexPath.section];cell.textLabel.font = [UIFont systemFontOfSize:12.0];cell.textLabel.textAlignment = NSTextAlignmentLeft;return cell;
}- (void)pressUp:(UIButton *)btn {if (btn.tag == 1002) {[btn setImage:[UIImage imageNamed:@"shou.png"] forState:UIControlStateNormal];_tableView.frame = CGRectMake(270, 200, 95, 20);btn.tag--;} else {[btn setImage:[UIImage imageNamed:@"fang.png"] forState:UIControlStateNormal];_tableView.frame = CGRectMake(270, 200, 95, 80);btn.tag++;}
}

折叠cell—demo

http://www.yidumall.com/news/27874.html

相关文章:

  • 成都营销型网站b2b是什么意思
  • 丰台路网站建设网络推广方法大全
  • wordpress a购物车插件专业整站优化
  • wordpress清除缓存天津网站建设优化
  • 网站更换模板互联网推广员是做什么的
  • 使用h5做的学习网站源码百度seo搜索引擎优化方案
  • 800字以上网站设计方案自助快速建站
  • 做网站怎建立ftp和数据库网站排名优化
  • 网站建设资质广告公司主要做什么
  • 网站开发开什么票seo怎么优化
  • 商城网站建设要求怎么提高关键词搜索权重
  • 出版社网站必须做企业可信认证嘛厦门网
  • 网站安全证书过期怎么处理深圳网页设计公司
  • 腾讯qq网页版网站seo推广营销
  • 湖北省城乡和住房建设厅官方网站头条新闻最新消息
  • 怎么查网站备案号今天的新闻主要内容
  • 网站内容营销百度账号注册入口
  • 三丰云服务器汕头seo管理
  • 都有哪些网站可以做推广中国seo关键词优化工具
  • 网站优化seo四个建议文库百度登录入口
  • 免费视频网站怎么赚钱杭州百度推广代理商
  • 做网上夫妻去哪个网站百度爱采购平台官网
  • 付公司制作网站费怎么做凭证电商关键词排名优化怎么做?
  • 怎么用网站的二级目录做排名aso排名
  • wordpress所有标签关键词优化怎么做
  • 做c语言的网站网推什么平台好用
  • 北京php网站制作北京seo优化费用
  • 推荐几个看黄的网站专业恶意点击软件
  • 网站转小程序武汉seo引擎优化
  • 西安模板网站建设套餐个人网络销售平台