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);

    }

  • 相关阅读:
    重构drf后的环境变量配置
    分离的前后台交互
    虚拟环境的搭建
    Python
    Python
    Python
    Python操作MongoDb数据库
    Python操作SQLite/MySQL/LMDB
    数据库-如何创建SQL Server身份验证用户
    Python
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/5742390.html
Copyright © 2011-2022 走看看