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

        }

    }

     

  • 相关阅读:
    一道压强题
    考试习惯的审题+习题+电脑存放目录记录
    产品需求分类及KANO模型需求排序学习
    马斯洛需求层次理论及其新拓展学习笔记
    12-JQuery学习之bind绑定事件
    11-JQuery学习之ready预加载事件
    09-JQuery学习之删除元素
    10-JQuery学习之遍历元素
    08-JQuery学习之创建元素和添加元素
    06-JQuery学习之操作元素的样式
  • 原文地址:https://www.cnblogs.com/developer-qin/p/4583426.html
Copyright © 2011-2022 走看看