美文网首页
转发一个大神的经验indexPathForCell返回nil的问

转发一个大神的经验indexPathForCell返回nil的问

作者: 叶熙雯 | 来源:发表于2018-05-15 16:27 被阅读0次

后来断点调试发现在ios7上

[self.tableview indexPathForCell:myCell] 返回了nil

在ios8中使用了

  - (void)selecttop:(id)sender{
    
    if ([sender isKindOfClass:[UIButton class]]) {
        
        UIView *view = sender;
        
        AppListCell *myCell = (AppListCell *)view.superview.superview;
        
        NSIndexPath * cellPath = [self.tableview indexPathForCell:myCell];
        
    }
    - (void)selecttop:(id)sender{
        
        if ([sender isKindOfClass:[UIButton class]]) {
            
            UIView *view = sender;
            
            while (![view isKindOfClass:[UITableViewCell class]]) {
                
                view = [view superview];
                
            }
            
            AppListCell *myCell = (AppListCell *)view;
            
            NSIndexPath * cellPath = [self.tableview indexPathForCell:myCell];
            
        }
    标记下
    
    真的是个坑!!!
    
    据说ios6上也是两个superview 就可以获取到!!!!

相关文章

网友评论

      本文标题:转发一个大神的经验indexPathForCell返回nil的问

      本文链接:https://www.haomeiwen.com/subject/ojhydftx.html