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 ...
随机推荐
- 3.1 as86汇编器
在开始讲述as86汇编器前,这本书引用内核中bootsect.s框架程序汇编代码来解释,记录下这一小段代码中不理解的地方,下面是这段实例代码: .globl begtext, begdata, beg ...
- iphone微信长按二维码识别不了
在安卓版的微信长按二维码可以识别(前提是你的微信版本到支持此功能),但是到了苹果版的微信就识别不了,经个人测试发现是缩放的问题: 1.设置了初始缩放设置为1,最大缩放值要>=1,不支持缩放.-- ...
- (function(){})(jQuery)的功能和用途?
1.为什么开发插件都这么写? 2.为什么要穿jQuery进去?在方法中直接用jquery的方法什么的不行吗? 1 首先(function(){})()这种写法 是创建了一个匿名的方法并立即执行(fun ...
- C盘hosts
# Copyright (c) - Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windo ...
- 【行为型】Command模式
命令模式是指将用户的请求封装成(命令)对象,从而可将用户不同的请求进行参数化.对这些请求排序或记录请求日志.以及支持回滚恢复操作.记得以前刚开始使用Photoshop时,就发现它的操作历史记录面板特别 ...
- UCOS 堆栈大小 计算 (堆栈的决定性因素)
决定栈空间的大小,不仅需要计算任务本身的需求(局部变量.函数调用等),还要计算最多中断嵌套层数(保存寄存器.中断服务程序中局部变量等) 原文地址:uCOS任务堆栈的深入分析.作者:jiecou 堆栈作 ...
- nginx 中location和root
nginx 中location和root,你确定真的明白他们关系? 2016-01-17 14:48 3774人阅读 评论(1) 收藏 举报 分类: linux(17) 版权声明:本文为博主原创文 ...
- 更改Altium中PCB大小/精确确定板子尺寸
使用原理图生成PCB后,Altium Designer会根据原理图大小自动生成一块黑色区域,还有一个在禁止布线层的方框,还有两段标注板子大小的线.下面说一下如何更改黑色区域的大小,还有如何精确确定板子 ...
- iOS 9之分屏多任务(Split View)
金田(github 示例源码) 多任务(multitasking)算是iOS9中最引人瞩目的核心新特性了,之前越狱版用户就用过类似的插件,微软的 苏菲 (Windows Surface)系列也有分屏多 ...
- U8800安装软件显示无效的URI问题
看到很多人遇到这个问题,其中包括我自己,最后找到可行的解决办法,现整理出来一个新帖,有同样问题的U友可以参考下. 手机先连接电脑,进入USB存储状态,然后在计算机上找到SD卡目录下的.android_ ...