iOS 点击cell下拉
iOS 点击cell下拉
代码如下:
#import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, copy) NSMutableArray *muArr;
@property (nonatomic, copy) NSMutableArray *boolArray;
@property (nonatomic, strong) UITableView *tableView; @end @implementation ViewController
#pragma mark - LifeCycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor whiteColor];
NSArray *array1 = @[@"",@"",@"",@"",@""];
NSArray *array2 = @[@"a",@"b",@"c",@"d",@"e",@"f"];
[self.muArr addObject:array1];
[self.muArr addObject:array2]; for (int i = ; i < self.muArr.count; i++) {
[self.boolArray addObject:@"no"];
}
[self.view addSubview:self.tableView];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - UITableViewDataSource and ITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.muArr.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//如果self.boolArray的内容为“yes”,返回self.muArr中某个数组的个数,否则返回2
if ([self.boolArray[section] isEqualToString:@"yes"]) {
return [[self.muArr objectAtIndex:section] count];
} else {
return ;
}
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"cellID";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
/*
else {
//如果不增加下面这个判断,tableview 再滑动后,会有重影,或者在被选中后会有重影
NSArray *views = [cell subviews];
for (UIView *obj in views) {
if (obj.tag==1000 || obj.tag==2000) {
NSLog(@"cell 要删除的子画面是:%@",[obj class]);
[obj removeFromSuperview];
}
}
}
*/
//显示每个section的第一个
if ([[self.muArr objectAtIndex:indexPath.section] count] > indexPath.row) {
cell.textLabel.text = [[self.muArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
}
//每个section的indexPath.row == 1显示为“更多”
if ([self.boolArray[indexPath.section] isEqualToString:@"no"] && indexPath.row == &&
[[self.muArr objectAtIndex:indexPath.section] count] != ) {
cell.textLabel.text = nil;
cell.textLabel.text = @"更多";
}
return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray *array = [[NSMutableArray alloc] init];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow: inSection:indexPath.section]]; if ([self.boolArray[indexPath.section] isEqualToString:@"no"]) {
self.boolArray[indexPath.section] = @"yes";
cell.textLabel.text = [[self.muArr objectAtIndex:indexPath.section] objectAtIndex:];
for (NSInteger i = ; i < [[self.muArr objectAtIndex:indexPath.section] count]; i++) {
NSIndexPath *index = [NSIndexPath indexPathForRow:i inSection:indexPath.section];
[array addObject:index];
}
[self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
}else{
self.boolArray[indexPath.section] = @"no";
cell.textLabel.text = @"更多";
for (NSInteger i = ; i < [[self.muArr objectAtIndex:indexPath.section] count]; i++) {
NSIndexPath *index = [NSIndexPath indexPathForRow:i inSection:indexPath.section];
[array addObject:index];
}
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
}
} - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[self.muArr objectAtIndex:indexPath.section] count] == ) {
return nil;
}
if ([self.boolArray[indexPath.section] isEqualToString:@"yes"]) {
return indexPath;
}else{
if (indexPath.row == ) {
return indexPath;
}else{
return nil;
}
}
} #pragma mark - Getter and Setter
- (NSMutableArray *)muArr {
if (!_muArr) {
_muArr = [[NSMutableArray alloc] init];
}
return _muArr;
} - (NSMutableArray *)boolArray {
if (!_boolArray) {
_boolArray = [[NSMutableArray alloc] init];
}
return _boolArray;
} - (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
} @end
iOS 点击cell下拉的更多相关文章
- ios学习--iphone 实现下拉菜单
原文地址:ios学习--iphone 实现下拉菜单作者:sdglyuan00 #import @interface DropDown1 : UIView <</span>UITabl ...
- js (单个的)点击式下拉菜单
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- iOS开发——UI篇&下拉弹出列表选择项效果
下拉弹出列表选择项效果 右边菜单中的按键,点击弹出一个列表可选择,选择其中一个,响应相应的事件并把文字显示在右边的菜单上:弹出下拉效果使用LMDropdownView插件,可以用POD进行加载pod ...
- 点击select下拉框获取option的属性值
select下拉框作为前端开发者应该是经常使用的,最近在项目中遇到这样的情况,点击下拉框选项,需要获取所点击的option的属性值,当时想很简单啊,给option加一个点击事件不就行了,然后就加了一下 ...
- 将select的默认小三角替换成别的图片,且实现点击图片出现下拉框选择option
最近做项目,要求修改select下拉框的默认三角样式,因为它在不同浏览器的样式不同且有点丑,找找网上也没什么详细修改方法,我就总结一下自己的吧. 目标是做成下图效果: 图一:将默认小三角换成红圈的三角 ...
- 点击select下拉框,触发事件
<div class="controls moneycheck floatleft"> <select class="span12 chosen_cat ...
- ios一个自定义的下拉多选菜单
前段时间项目刚好要做到条件筛选菜单,正好找到一些别人写的,结合自己实际需求进行优化修改,一个实用的多条件筛选菜单,根据其他的下拉进行一些改进. 点击后返回点击文字显示 github地址:https:/ ...
- js 导航栏多项点击显示下拉菜单代码
<!DOCTYPE html> <html> <head> <title>Dropdown</title> <!--<link ...
- 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)
从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...
随机推荐
- PHPCMS 插件开发教程及经验谈
虽说 PHPCMS 开源,但其它开发文档及参考资料实在少得可怜.进行二次开发时,自己还得慢慢去研究它的代码,实在让人郁闷. PHPCMS 的“Baibu/Google地图”实在有待改进,对于数据量比较 ...
- git clone 远程分支
先初始化一个git 仓库 命令:git init git clone 相应的地址 这样就会形成一个.git 隐藏文件夹 一定要注意的,要进入到子文件夹去git checkout feature/0. ...
- opencv中Mat类型数据操作与遍历
Mat作为opencv中一种数据类型常常用来存储图像,相对与以前的IplImgae类型来说,Mat类型省去了人工的对内存的分配与释放,转而自动分配释放.Mat Class主要包括两部个数据部分:一个是 ...
- OC 代码规范
我们写出来的代码会给很多人看,为了使代码清晰简洁,方便阅读理解,都会统一遵从一定的代码规范,Objective-C同样如此. 主要参考规范: 1. Google Objective-C Sty ...
- Qt中如何固定窗口的大小?
这个是从网上转载过来的,我第一次看到的在如下网页:http://blog.csdn.net/cgb0210/article/details/5712980 这里我记录一下,留以后查阅. 一种方法是设 ...
- 用PYTHON实现将电脑里的所有文件按大小排序,便于清理
嘿嘿,慢慢找到写代码的感觉了. 这个小程序涉及的东东还是很多的,数据结构的设计,错误的处理,快速字典排序,文件数值调整.... import os,os.path import glob SUFFIX ...
- Android中支持的常用距离单位
px(像素):每个px对应屏幕上的一个点.dip或dp(device independent pixels,设备独立像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dip=1px.但 ...
- WPF 自己动手来做安装卸载程序
原文:WPF 自己动手来做安装卸载程序 前言 说起安装程序,这也许是大家比较遗忘的部分,那么做C/S是小伙伴们,难道你们的程序真的不需要一个炫酷的安装程序么? 声明在先 本文旨在教大家以自己的方式实现 ...
- 为何某些公司不允许使用C++ STL?
说几个STL的缺点吧,虽然都是在比较极端的情况下出现,但是对于一些大项目还是会遇到的 1. 代码膨胀问题每一个实例化过的模板类,都会膨胀出一份独立的代码,比如std::vector<std::s ...
- Linux系统编程(37)—— socket编程之UDP服务器与客户端
典型的UDP客户端/服务器通讯过程: 编写UDP Client程序的步骤 1.初始化sockaddr_in结构的变量,并赋值.这里使用"8888"作为连接的服务程序的端口,从命令行 ...