ios uitableview button 获取cell indexpath.row
在iOS7下面已经无效,因为iOS7的层级关系发生变化
UITableViewCell->UITableViewCellScrollView->UITableViewCellContentView->Your custom view
下面有2种方法解决这个问题
-(void) visitButtonClicked:(UIButton *)sender
{
// 第一种,兼容所有的版本
UIView *superView = sender.superview;
UITableViewCell *foundSuperView = nil;
while (nil != superView && nil == foundSuperView) {
if ([superView isKindOfClass:[UITableViewCell class]]) {
foundSuperView = (UITableViewCell *)superView;
} else {
superView = superView.superview;
}
}
NSLog(@"founda = %d", [_tableView indexPathForCell:foundSuperView].row);
}
// 第2种,不兼容iOS7以下
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
NSLog(@"foundb = %d", [_tableView indexPathForCell:cell].row);
}
ios uitableview button 获取cell indexpath.row的更多相关文章
- IOS 通过button获取cell
在使用tableview时,有时我们需要在cell中添加button和label,以便添加某项功能,而且往往点这个button的方法中需要知道button所在cell中label内存放的值. 一般而言 ...
- iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
在section=10:row=1:的UITableView中,每一个cell都带有一个按钮,例如如下的图片一样每一个cell中都有一个“进入店铺的按钮”,但是如果我点击相应的cell要进入对应的店铺 ...
- button 获取 cell
- (void)cellBtnClicked:(id)sender event:(id)event { NSSet *touches =[event allTouches]; ...
- iOS 获取自定义cell上按钮所对应cell的indexPath.row的方法
在UITableView或UICollectionView的自定义cell中创建一button,在点击该按钮时知道该按钮所在的cell在UITableView或UICollectionView中的行数 ...
- iOS UITableView获取特定位置的cell
代码地址如下:http://www.demodashi.com/demo/13307.html 一.tableView双级联动 以上两种效果比较类似,实现的关键在于都是需要获得在滑动过程中滑动到tab ...
- ios UITableView 获取点击cell对象
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITabl ...
- objc_setAssociatedObject获取cell上button对应所在的行
#import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property (weak, nonatomic) IBOu ...
- iOS开发UITableView的动画cell
1.动画cell 针对cell的动画,在Delegate中对cell的layer进行操作: 2.实现代码 #import "ViewController.h" #import &q ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
随机推荐
- Winform打砖块游戏制作step by step第二节---.画挡板
一 引子 为了让更多的编程初学者,轻松愉快地掌握面向对象的思考方法,对象继承和多态的妙用,故推出此系列随笔,还望大家多多支持. 预备知识,无GDI画图基础的童鞋请先阅读一篇文章让你彻底弄懂WinFor ...
- UITableView的HeaderView和FooterView
header通过下面两个代理方法设置 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege ...
- osg节点统计方法(点数 面数) 【转】
void statusNode(osg::ref_ptr<osg::Node> node,int& verNum,int& faceNum){ osg::ref_ptr&l ...
- ElasticSearch搜索
1.搜索---最基本的工具 我们可以将一个 JSON 文档扔到 Elasticsearch 里,然后根据 ID 检索.但 Elasticsearch 真正强大之处在于可以从无规律的数据中找出有意义的信 ...
- 读取Properties文件简易代码
public class Utils { private static Properties props = new Properties(); static { ClassLoader classL ...
- 配置php扩展memcache
配置php扩展memcache 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 php-5.5.38 ...
- 将 xml 文件 转为 DataTable
private static DataTable CreateDataTable(string table) { DataSet dataSet = new DataSet(); string dat ...
- 输出C语言中 变量的类型
使用gcc的警告信息间接知道变量的类型 #include <stdio.h> #include <stdlib.h> #include <stddef.h> #in ...
- 【转】oracle建立本地数据库
来到公司的这段时间,在项目的开发过程中一直连接的是远程的oracle数据库,现在开始轮到自己做毕业设计了,自己想采用Oracle数据库,就想建立本地的数据库. 当然了,首先是自己先装Oracle客户端 ...
- CDN原理实现详情
CDN真是个好东西,但是究竟是怎么实现的呢, 学习下吧 首先浏览器发起请求 Dns解析寻找服务器资源 使用CDN加速的内容会被放到不同的服务器上 根据用户的请求来判断 -- 算了表达不清楚,看图吧! ...