zoukankan      html  css  js  c++  java
  • 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);

    }

  • 相关阅读:
    生成器函数
    初识函数
    格式化输出
    流程控制-while循环
    流程控制if语句
    Python入门
    Eclipse搭建C++开发环境
    Android SQLite基本用法
    Android拍照后更新相册
    操作系统相册和获取相册路径
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/5742390.html
Copyright © 2011-2022 走看看