0
我正在嘗試使用3D Touch,除了下面的功能,一切都很好,當滾動時我無法獲得正確的值indexPath
和indexPathForRow(at: location)
。此功能不能說用戶是否滾動表格,並且始終將用戶在應用中可以看到的第一行設置爲第一行。indexPathForRow不會返回正確的值
我的代碼:
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = workoutTable?.indexPathForRow(at: location) else {return nil }
guard let cell = workoutTable?.cellForRow(at: indexPath) else {return nil }
guard let workoutDetailPeek = storyboard?.instantiateViewController(withIdentifier: "WorkoutDetailPeek") as? WorkoutDetailPeek else {print("else31"); return nil }
workoutDetailPeek.workoutId = "\(Int(workout[(indexPath as NSIndexPath).row].workoutId)!-2)"
workoutDetailPeek.preferredContentSize = CGSize(width: 400.0, height: 267.0)
previewingContext.sourceRect = cell.frame
return workoutDetailPeek
}
我一直通過不同的3D觸控實現,但這個功能似乎每個人都工作正常,除了我。