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

        }

    }

     

  • 相关阅读:
    填坑!!!virtualenv 中 nginx + uwsgi 部署 django
    树的遍历与递归
    Python 函数的参数
    virtualbox安装增强功能时【未能加载虚拟光盘】
    深入理解Python中的生成器
    Genymotion下载慢或者下载失败的解决办法
    Python3 多线程的两种实现方式
    Java 多线程
    关于"裁员与面试"的个人感悟吧
    三、由简单对象组装复杂实例的模式:建造者模式
  • 原文地址:https://www.cnblogs.com/developer-qin/p/4583426.html
Copyright © 2011-2022 走看看