[英]Implement peek and pop to multiple UITableView in one UIViewController
我在一個ViewController和一個UIView
有兩個UITableView
,並且嘗試實現Peek和Pop,但是每次我注冊這兩個表時,它僅適用於第一個表。 以下是我注冊UITableViews
:
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
}
上面的方法不起作用。 (這可能是錯誤的實現,對我來說沒有任何意義)。 我也嘗試了此解決方案,但未按預期工作。 我正在尋找的是這樣的:
if sourceView == tableView {
//first tableView implementation
} else {
//second tableView implementation
}
任何幫助表示贊賞。 最近4個小時我一直在頭。
我可能會嘗試僅注冊一次預覽,而源視圖只是您的視圖:
registerForPreviewing(with: self, sourceView: self.view)
然后在您的previewingContext
方法中將此點轉換為每個tableView以確定它是哪個:
let tableViewPoint = self.view.convert(location, to: self.tableView)
if let indexPath1 = self.tableView.indexPathForRow(at: tableViewPoint) {
// Point is within first table - get the cell at this indexPath and handle
}
else {
let tableViewPoint2 = self.view.convert(location, to: self.tableView2)
if let indexPath2 = self.tableView2.indexPathForRow(at: tableViewPoint2) {
// Point is within second table - get the cell at this indexPath and handle
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.