indexPathForCell returning NULL under IOS 7, works fine under IOS 6

后端 未结 1 1908
無奈伤痛
無奈伤痛 2021-02-13 05:36

I\'m hoping now apps for IOS 7 are being accepted by Apple we can talk about it?

I\'m trying to fix my app so it works on IOS 7 and have made some very good progress thi

1条回答
  •  孤街浪徒
    2021-02-13 06:02

    It's usually safer to make no assumptions about the view hierarchy of a cell. In the past, I've used a category with methods like this on UIView to find the superview which is a cell:

    - (UIView*)ancestorOrSelfWithClass:(Class)cls {
      if ([self isKindOfClass:cls]) {
        return self;
    
      } else if (self.superview) {
        return [self.superview ancestorOrSelfWithClass:cls];
    
      } else {
        return nil;
      }
    }
    

    So you'll ask for [sender ancestorOrSelfWithClass:[UITableViewCell class]] to get the actual cell, and it'll work no matter what hierarchy exists within the cell.

    0 讨论(0)
提交回复
热议问题