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

  1. IOS 通过button获取cell

    在使用tableview时,有时我们需要在cell中添加button和label,以便添加某项功能,而且往往点这个button的方法中需要知道button所在cell中label内存放的值. 一般而言 ...

  2. iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section

    在section=10:row=1:的UITableView中,每一个cell都带有一个按钮,例如如下的图片一样每一个cell中都有一个“进入店铺的按钮”,但是如果我点击相应的cell要进入对应的店铺 ...

  3. button 获取 cell

        - (void)cellBtnClicked:(id)sender event:(id)event {     NSSet *touches =[event allTouches];      ...

  4. iOS 获取自定义cell上按钮所对应cell的indexPath.row的方法

    在UITableView或UICollectionView的自定义cell中创建一button,在点击该按钮时知道该按钮所在的cell在UITableView或UICollectionView中的行数 ...

  5. iOS UITableView获取特定位置的cell

    代码地址如下:http://www.demodashi.com/demo/13307.html 一.tableView双级联动 以上两种效果比较类似,实现的关键在于都是需要获得在滑动过程中滑动到tab ...

  6. ios UITableView 获取点击cell对象

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITabl ...

  7. objc_setAssociatedObject获取cell上button对应所在的行

    #import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property (weak, nonatomic) IBOu ...

  8. iOS开发UITableView的动画cell

    1.动画cell 针对cell的动画,在Delegate中对cell的layer进行操作: 2.实现代码 #import "ViewController.h" #import &q ...

  9. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

随机推荐

  1. 使用ubifs格式的根文件系统---过程记录

    配置内核,使其支持ubifs文件系统 1)Device Drivers  --->Memory Technology Device (MTD) support  --->UBI - Uns ...

  2. Asp.net+EF

    EFRepositoryBase using System; using System.Collections.Generic; using System.Data; using System.Dat ...

  3. onWebView检查网页中文

    问题:要检查网页中的一段文本: 开始我是这样写的: private final static String SPECIFIED_TEXT = "这个是一段中文"; onWebVie ...

  4. Android 使用SQLite本地数据库

    参考:http://blog.csdn.net/jianghuiquan/article/details/8569252 在Android平台上,集成了一个嵌入式关系型数据库—SQLite.以SQLi ...

  5. iOS学习4_UITableView的使用

    UITableView相当于Android里面的ListView.但功能却比ListView强大太多. 使用UITableView须要指定数据源和代理. 1.显示全部的行 遵守UITableViewD ...

  6. Linux如何查看当前占用CPU或内存最多的几个进程

    1. ps命令 ps -aux | sort -k4nr | head -N *命令详解: 1. head:-N可以指定显示的行数,默认显示10行. 2. ps:参数a指代all——所有的进程,u指代 ...

  7. EarlyZ disable( earlyz失效

    There are a few ways to disable EarlyZ list here: Shader depth output disabled Alpha test with depth ...

  8. Java 中 ConcurrentHashMap 原理分析

    一.Java并发基础 当一个对象或变量可以被多个线程共享的时候,就有可能使得程序的逻辑出现问题. 在一个对象中有一个变量i=0,有两个线程A,B都想对i加1,这个时候便有问题显现出来,关键就是对i加1 ...

  9. 【Hadoop】Hadoop MR 自定义分组 Partition机制

    1.概念 2.Hadoop默认分组机制--所有的Key分到一个组,一个Reduce任务处理 3.代码示例 FlowBean package com.ares.hadoop.mr.flowgroup; ...

  10. ES,ZK,Mysql相关参数优化

    1.ES 内存调优: vi config/jvm.options -Xms16g -Xmx16g 2.Zookeeper参数配置调优 2.1\在conf目录下 vi java.env export J ...