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

    }

  • 相关阅读:
    IDEA快捷键收集
    Jmeter录制HTTPS
    Jmeter 线程组、运行次数参数化
    fiddler 抓取iphone发出的http和https包
    Appium 点击屏幕
    安卓程序如何保证低内存下依然存在
    listview
    数据库操作
    数据存储
    测试
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/5742390.html
Copyright © 2020-2023  润新知