3

在我的测试演示中,我将 UITableView 放入情节提要中的 UIViewController 中。当我在我的 iPhone 上测试演示时,我在 tableView 中按下了一个单元格,我在图片中收到了这个错误

错误的单元格视图

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?方法中,我使用

guard let indexPath = tableView.indexPathForRowAtPoint(location), cell = tableView.cellForRowAtIndexPath(indexPath) else { return nil }在 UITableView 中获取按下的单元格。

如果你能给我任何答案,我真的很感激!

4

1 回答 1

14

当您注册您的源视图时,您是添加视图控制器的视图还是您的表格视图?我在集合视图上遇到了类似的问题,但是一旦我注册了实际视图而不是视图控制器的视图,行为就得到了纠正。

所以换句话说..

这给了我错误的细胞

registerForPreviewingWithDelegate(self, sourceView:self.view)

这纠正了行为

registerForPreviewingWithDelegate(self, sourceView:self.tableView)

于 2015-10-26T21:06:33.140 回答