0
我在一个ViewController和UIView
中有两个UITableView
,我试图实现Peek和Pop,但每次注册两个表时,它只能用于第一个表。下面就是我在注册UITableViews
:在一个UIViewController中实现偷看和弹出到多个UITableView
if traitCollection.forceTouchCapability == UIForceTouchCapability.available {
registerForPreviewing(with: self, sourceView: self.tableView2)
registerForPreviewing(with: self, sourceView: self.tableView)
}
我viewControllerForLocation
:
if tableView.point(inside: tableViewPoint, with: nil) {
guard let indexPath = self.tableView.indexPathForRow(at: location) else { return nil }
guard let cell = self.tableView.cellForRow(at: indexPath) else { return nil }
let storyBoard = UIStoryboard(name: "Home", bundle: nil)
guard let previewViewController = storyBoard.instantiateViewController(withIdentifier: "article_page") as? ArticleViewController else { return nil }
previewViewController.preferredContentSize = CGSize(width: 0.0, height: 550)
previewViewController.passedValue = article_ids[(indexPath as NSIndexPath).row]
previewingContext.sourceRect = cell.frame
return previewViewController
} else {
guard let indexPath = self.tableView2.indexPathForRow(at: location) else { return nil }
guard let cell = self.tableView2.cellForRow(at: indexPath) else { return nil }
let storyBoard = UIStoryboard(name: "Home", bundle: nil)
guard let previewViewController = storyBoard.instantiateViewController(withIdentifier: "article_page") as? ArticleViewController else { return nil }
previewViewController.preferredContentSize = CGSize(width: 0.0, height: 550)
if indexPath.row == 0 {
previewViewController.passedValue = 1001
} else {
previewViewController.passedValue = weekly_article_id_[(indexPath as NSIndexPath).row - 1]
}
previewingContext.sourceRect = cell.frame
return previewViewController
}
以上不起作用。 (它可能是错误的实现,因为它对我没有任何意义)。我也尝试了this解决方案,但它没有按预期工作。我正在寻找的东西是这样的:
if sourceView == tableView {
//first tableView implementation
} else {
//second tableView implementation
}
任何帮助表示赞赏。我在过去的4个小时里一直在努力。
工程就像一个魅力!谢谢! –