我正在尝试在我的快速代码中实现 3D Touch Peek and Pop。当用户在查看视图上按得更深时,将出现一系列预览操作(共享、更新、删除)。
我需要的是当用户选择更新操作将移动到 UpdateView 控制器,但它不断崩溃。
这是我的代码:
HomePeakViewController.swift
let item3 = UIPreviewAction(title: "Update", style: .Default) { (action:UIPreviewAction, vc:UIViewController) -> Void in
print("Update")
let nb:BookAppointmentViewController = BookAppointmentViewController(nibName: "BookAppointmentViewController", bundle: nil)
let root = UIApplication.sharedApplication().keyWindow?.rootViewController
root?.presentViewController(nb, animated: true, completion: nil)
HomeViewController.swift 中的 POP 方法
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
let Homepeak = HomePeakViewController()
showViewController(Homepeak, sender: self)
}
我也尝试了这段代码来移动到更新屏幕,但它给了我(致命错误:在展开可选值时意外发现 nil)。
var top = UIApplication.sharedApplication().keyWindow?.rootViewController
let test = AppointmentDetailsViewController()
top!.presentViewController(test, animated: true, completion: {})