I'm trying to implement 3D Touch Peek and Pop in my swift code. When the user presses deeper on the peek view, array of preview actions will appear (Share, Update, Delete).
What I need is when user select Update action will move to UpdateView controller, but it keeps on crashing.
Here is my code:
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)
POP method in HomeViewController.swift
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
let Homepeak = HomePeakViewController()
showViewController(Homepeak, sender: self)
}
I tried this code as well to move to Update screen, but it gives me (fatal error: unexpectedly found nil while unwrapping an Optional value).
var top = UIApplication.sharedApplication().keyWindow?.rootViewController
let test = AppointmentDetailsViewController()
top!.presentViewController(test, animated: true, completion: {})