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下拉的更多相关文章

  1. ios学习--iphone 实现下拉菜单

    原文地址:ios学习--iphone 实现下拉菜单作者:sdglyuan00 #import @interface DropDown1 : UIView <</span>UITabl ...

  2. js (单个的)点击式下拉菜单

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. iOS开发——UI篇&下拉弹出列表选择项效果

    下拉弹出列表选择项效果 右边菜单中的按键,点击弹出一个列表可选择,选择其中一个,响应相应的事件并把文字显示在右边的菜单上:弹出下拉效果使用LMDropdownView插件,可以用POD进行加载pod  ...

  4. 点击select下拉框获取option的属性值

    select下拉框作为前端开发者应该是经常使用的,最近在项目中遇到这样的情况,点击下拉框选项,需要获取所点击的option的属性值,当时想很简单啊,给option加一个点击事件不就行了,然后就加了一下 ...

  5. 将select的默认小三角替换成别的图片,且实现点击图片出现下拉框选择option

    最近做项目,要求修改select下拉框的默认三角样式,因为它在不同浏览器的样式不同且有点丑,找找网上也没什么详细修改方法,我就总结一下自己的吧. 目标是做成下图效果: 图一:将默认小三角换成红圈的三角 ...

  6. 点击select下拉框,触发事件

    <div class="controls moneycheck floatleft"> <select class="span12 chosen_cat ...

  7. ios一个自定义的下拉多选菜单

    前段时间项目刚好要做到条件筛选菜单,正好找到一些别人写的,结合自己实际需求进行优化修改,一个实用的多条件筛选菜单,根据其他的下拉进行一些改进. 点击后返回点击文字显示 github地址:https:/ ...

  8. js 导航栏多项点击显示下拉菜单代码

    <!DOCTYPE html> <html> <head> <title>Dropdown</title> <!--<link ...

  9. 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)

    从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...

随机推荐

  1. MySQL重置root用户密码的方法(转)

    本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...

  2. idHTTP最简洁的修改和取得Cookie例子

    procedure TForm1.Button1Click(Sender: TObject); var HTTP: TidHTTP; html, s: string; i: integer; begi ...

  3. php如何做数据库攻击

    PHP mysql_real_escape_string() 函数 PHP MySQL 函数 定义和用法 mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的 ...

  4. 查看文件系统类型的Linux命令

    不需挂载就能查看的命令:   1. file  [root@localhost dev]# file -s /dev/sda1 /dev/sda1: Linux rev 1.0 ext4 filesy ...

  5. C程序设计语言练习题1-18

    练习1-18 编写一个程序,删除每个输入行末尾的空格及制表符,并删除完全是空格的行. 代码如下: #include <stdio.h> // 包含标准库的信息. #define MAXLI ...

  6. PHP浮点数的一个常见问题的解答

    作者: Laruence 本文地址: http://www.laruence.com/2013/03/26/2884.html 转载请注明出处 关于PHP的浮点数, 我之前写过一篇文章: 关于PHP浮 ...

  7. Facebook和Google如何激发工程师的创造力

    http://taiwen.lofter.com/post/664ff_ad8a15 今天终于“朝圣”了两个伟大的公司——Facebook和Google,对创造力和驱动力的来源有了更多的理解,尤其是对 ...

  8. Windows下的SVN环境搭建详解

    前言:最近因为要和其他人合作开发项目,所以花时间搭建了SVN的环境. 因为是初次使用SVN,对于SVN的环境搭建很不熟悉,再加上网上的教程都介绍的比较粗略,导致前前后后重做了几次. 当然最终是搭建成功 ...

  9. 对libssh的golang 封装 ssh2go

    ssh2go 是对libssh的go语言绑定.libssh作为ssh的实现库,支持SSHv2和SSHv1的客户.服务端实现,通过libssh你可以远程执行程序.拷贝文件等等. ssh2go不像其他go ...

  10. Android中观察者模式的升入理解

    以前对Java中的观察者模式只知道一点皮毛,在接触Android的过程中,逐渐认识到观察者模式是如此的重要,android中许多地方都用到了观察者模式例如ContentResolver操作,来总结一下 ...