zoukankan      html  css  js  c++  java
  • 如何通过Button获取UITableViewCell

    发现一个奇怪的问题:

    手机(ios7)

    2015-06-17 15:11:29.323 ***[1412:60b]  [btn superview] =  UITableViewCellContentView 

    2015-06-17 15:11:29.324 ***[1412:60b]  [[[btn superview]superview]class] = UITableViewCellScrollView

     

     

    模拟器:ios8

    2015-06-17 15:12:54.614 MyQ[7862:125756]  [btn superview] =  UITableViewCellContentView 

    2015-06-17 15:12:54.614 MyQ[7862:125756]  [[[btn superview]superview]class] = EditTableViewCell

     

    百度了一下发现:

    http://www.cocoachina.com/bbs/read.php?tid=232335

    提供的方法:

    OffLineTableViewCell *cell = nil;
        if (IsIOS7) {
            UIView *view = [btn superview];
            UIView *view2;
            if (IsIOS8) {
                view2 = view;
            }else{
                view2 = [view superview];
            }
            cell =  (OffLineTableViewCell *)[view2 superview];
        }else{
            cell = (OffLineTableViewCell *)[btn superview];
        }
    

    果然太麻烦,弃用,换成现在这个,亲测可用。。。

      

    这个方法真的是太靠谱了,这样还省了我要在TableViewCell中定义delegate。太赞!

    还有一个支持这个方法的原因:如果删除tableviewcell中的某个数据后,再点btn可能会出现数组越界的情况。

    -(void)cellBtnClicked:(id)sender event:(id)event

    {

        NSSet *touches = [event allTouches];

        UITouch *touch = [touches anyObject];

        CGPoint currentTouchPosition = [touch locationInView:favTableView];

        NSIndexPath *indexPath =[favTableView indexPathForRowAtPoint:currentTouchPosition];

        if (indexPath!=nil) {

            ProfileViewController *profile = [[ProfileViewController alloc]init];

            profile.empInfoempSearchResultArray[indexPath.row]; //error

            [self.navigationController pushViewController:profile animated:YES];

            

            

            RootViewController *rootVC = (RootViewController *) self.tabBarController;

            [rootVC showTabBar:NO];

        }

    }

     

  • 相关阅读:
    51nod——1174 区间中最大的数(ST)
    「学习笔记」Ubuntu 下手动安装 Emacs
    [学习笔记] 2-SAT
    「解题报告」 [JXOI2017]数列 (DP)
    「解题报告」 [UOJ#62] 怎样跑得更快 (莫比乌斯反演)
    「学习笔记」杜教筛
    「学习笔记」Dirichlet卷积 莫比乌斯函数 莫比乌斯反演
    「学习笔记」向量外积(叉乘)
    网络流24题
    「解题报告」[网络流24题] 16.数字梯形问题 (最大费用最大流)
  • 原文地址:https://www.cnblogs.com/developer-qin/p/4583426.html
Copyright © 2011-2022 走看看