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 ...
随机推荐
- mongo学习整理
mongo做为NOSQL家族中一员,被广泛使用以及应用到生产环境中,有其出色的性能.关系型数据库(RDBMS )在互联网中依然是不可替代的一部分,mongo基于NOSQL的特性,在程序中RDBMS不适 ...
- maven 整理
1. 打包命令: mvn package -DskipTests 2. 发布命令: mvn deploy -DperformRelease=true
- 读书笔记 -part1
自从毕业以后到现在~看的书是越来越少了 の其实好像貌似从来没有认认真真的看书 除非工作遇到难于解决的问题迫不得已才去翻书看 有些问题也是莫名其妙的就这样解决了 于是乎被人美名其曰“高人”或&quo ...
- asp.net core VS goang web[修正篇]
先前写过一篇文章:http://www.cnblogs.com/gengzhe/p/5557789.html,也是asp.net core和golang web的对比,热心的园友提出了几点问题,如下: ...
- 《EM-PLANT仿真技术教程》读书笔记(持续更新中)
1.在系统分析过程中,必须考虑系统所处的环境,因此划分系统与环境的边界是系统分析的首要任务 2.模型可以分为物理模型和数学模型.数学模型可以分为解析模型.逻辑模型.网络模型以及仿真模型.模型可以分为离 ...
- SwitchySharp怎样设置 ( proxy switch!的设置与使用方法)
规则列表URL https://autoproxy-G{过}F{滤}Wlist.googlecode.com/svn/trunk/G{过}F{滤}Wlist.txt 注:不同的代{过}{滤}理 相 ...
- 转:6款Java转C#的最佳工
原文来自于:http://designzum.com/2014/03/27/best-tools-to-convert-java-to-c-source-code/ ava is the class ...
- 委托 delegate, 继承
c# 的委托就是说把函数当参数来传递. 这个在js完全就用不着搞什么委托东西,直接转就是了嘛.对不对!怎么录嘛! 一个函数,如果它的参数是函数,那么是这样子写的 public void method( ...
- BZOJ 4407 于神之怒加强版
http://www.lydsy.com/JudgeOnline/problem.php?id=4407 题意: 给下N,M,K.求 思路: 来自:http://blog.csdn.net/ws_y ...
- chrome 打不开网页
右键单击Chrome在桌面的快捷方式,在在但中选择“属性”,在对话框的“目标”项目中追加:-no-sandbox 大家比较熟悉的解决方法有配置 Hosts 文件和使用FQ软件两种,配置 Hos ...