我想窺視一個視圖控制器,它只有一個ImageView和一些標籤,但當用戶按下更難時,他們會彈出到ViewController,他們通常會已經有用戶只需點擊表格視圖單元格!Peek ViewController但彈出一個不同的ViewController - 三維Touch - Swift
我遇到的問題是viewControllerToCommit沒有索引路徑,我無法確定傳遞給新View Controller的內容。這是我的代碼至今:
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
let popViewController = self.storyboard?.instantiateViewController(withIdentifier: "ReadArticleViewController") as! ReadArticleViewController
popViewController.storyURL = //This is where i need to be able to get the index path so i can extract the url for the webview
self.show(popViewController, sender: self)
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = tableView.indexPathForRow(at: location) else {return nil}
let cell = tableView.cellForRow(at: indexPath) as! ArticleCell
let previewViewController = self.storyboard?.instantiateViewController(withIdentifier: "PeekViewController") as! PeekViewController
previewViewController.storyImage = cell.pictureView.image
previewViewController.storyTitle = cell.titleLabel.text
previewViewController.preferredContentSize = CGSize(width: view.frame.width, height: 300)
previewingContext.sourceRect = cell.frame
return previewViewController
}
我明白了,viewControllerToCommit中的信息包含我已經存儲在previewViewController中的屬性?我嘗試使用viewControllerToCommit.storyImage,那裏沒有任何東西,因爲它在我看來是錯誤的?我是否瞭解你> – Eli
你不能說'viewControllerToCommit.storyImage'。你必須對它真正的課程進行研究。如果這是一個PeekViewController,你會說'(viewControllerToCommit as!PeekViewController).storyImage'。 – matt
作品魅力!謝謝 :) – Eli