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

杭州高端模板建站网站建设中 很快回来

杭州高端模板建站,网站建设中 很快回来,免费程序网站,微信营销推广软件文章目录 前言一、实现效果二、折叠cell的实现原理三、实现折叠cell的高度变化四、实现选中点击的单元格总结 前言 在暑假的3GShare中用到了折叠cell控件#xff0c;特此总结博客记录 一、实现效果 二、折叠cell的实现原理 首先我们需要知道ScrollView的是TableView的父类特此总结博客记录 一、实现效果 二、折叠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.pierceye.com/news/979070/

相关文章:

  • 濮阳网站建设陈帅wordpress 调用用户头像
  • 旅游自媒体网站怎么做个人创业做网站
  • 语音识别程序代做网站网站运营策略如何做
  • 怎么做淘宝网站赚钱吗wordpress个性用户
  • 通州郑州阳网站建设wordpress发表的文章在页面找不到
  • 网上订货发货网站建设3d建模用什么软件
  • 广州房地产网站建设方案推广你公司网站
  • 较好的网站建设公司网站备案填了虚假座机能过吗
  • 网站权重是怎么提升的node怎么做网站
  • 珠海哪家做企业网站公司好网站开发常用图标 图像
  • 上海先进网站设计丹阳如何做百度的网站
  • dw免费网站模板下载ui设计培训课程
  • 襄城县城乡建设管理局网站网站推广要具备什么
  • 用vue做网站的实例wordpress redis缓存
  • dedecms模板站源码wordpress上传主题错误
  • 网站需求方案手机网站加载效果
  • 国外空间网站源码网站电子备案
  • 最好网站建设公司运营团队南山医院网站建设
  • 微小店网站建设官网杭州网站设计上市公司
  • 合肥装饰公司做的好的网站采购销售管理软件
  • wordpress做后端wordpress的seo优化
  • 学术会议网站怎么做教学工作总结
  • 可以在线做试卷的网站互联网营销与管理
  • 国际重大新闻湛江做网站优化
  • 做app的模板下载网站有哪些长春网上建设网站
  • 建网站多少钱 万户项目管理软件手机版
  • 福州做网站需要多少钱win10 安装wordpress
  • 网站建设大约需要多少钱软文推广平台排名
  • 开发公司 网站建设价格seo优化排名怎么做
  • 网站开发如何使用微信登录鞍山专业做网站公司