2017-09-27 82 views
3

有沒有人知道這個問題發生了什麼?因爲這個,我的手機停止刷卡。_shouldShowMenuForCell中的意外nil索引路徑

[斷言]意外的零指數 _shouldShowMenuForCell路徑:,這應該不會發生。細胞 ; baseClass = UITableViewCell;幀=(0 97.5; 375 130); alpha = 0;隱藏= YES; autoresize = W; gestureRecognizers =;層 =>

幫助!!!

+1

護理分享一些代碼? –

+0

這不是什麼特別的,只有VC與UItableView。使用在UITableViewCell的子類中實現的手勢識別器創建的單元格劃分工作正常,並且在顯示此日誌時開始出現問題。 – Piotr

回答

1

我將gestureRecognizer的滑動方法更改爲ScrollView,一切都很完美。

1

如果你的單元格是由 - 創建的[[[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil] lastObject];

並使用addSubview來顯示它。這個問題會發生。

我的解決方案是使用「addSubview:cell.contentView」,但沒有「addSubview:細胞」

0

我已經找到解決方案,甚至使用手勢識別創建刷卡細胞,在我的情況的問題(「意外的零索引路徑。在_shouldShowMenuForCell:,這是不可能發生的「)的出現,因爲這個功能:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { 
     for subview in self.subviews.reversed() { 
      if subview.frame.contains(point) { 
       return subview 
      } 
     } 

     return super.hitTest(point, with: event) 
} 

提示:工作液: Capturing touches on a subview outside the frame of its superview using hitTest:withEvent: