好的,我看到了你的代码,但你没有实现 3D Touch,首先你需要检查你的 viewDidLoad() 方法中是否有 3DTouch:
if( UIApplication.shared.keyWindow?.traitCollection.forceTouchCapability == .available{
registerForPreviewing(with: self, sourceView: view)
}
然后,实现Preview UIViewControllerPreviewingDelegate的delegate,你说的是用3dtouch弹出一个viewcontroller,在delegate中实现这个功能
extension:YourViewController:UIViewControllerPreviewingDelegate{
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
//Here's where you commit (pop)
//You are trying to show into tableview, the next code makes this
//For TableView
guard let indexPath = tableView?.indexPathForItem(at:location) else {
return nil }
guard let cell2 = tableview.cellForRow(at: indexPath) else { return nil }
guard let popVC = storyboard?.instantiateViewController(withIdentifier: "popVC") as? YourClassViewControllerToShow else { return nil }
let html = htmls[indexPath.row]
popVC.html = html
show(popVC, sender: self)
}
}
然后我将代码从 Detail.swift viewDidLoads() 切换到 viewWillAppear()
content.uiDelegate = self
content.navigationDelegate = self
let url = Bundle.main.url(forResource: result?.id, withExtension: "html", subdirectory: "Library")!
let request = URLRequest(url: url)
content.loadFileURL(url, allowingReadAccessTo: url)
content.load(request)
使用最后一个,您可以确保 web 视图在出现时始终刷新。