I am trying to implement 3d Touch and I want to navigate to a specific viewController in a Master - Detail app.
The viewController I am aiming to get to is the third controller in the hierarchy:
MasterViewController ----> SettingsViewController ----> ThirdViewController
I can access the ThirdViewController in normal operation through TabBarItem (connected via segue to SettingsViewController right from the IB) and then via a UIButton (connected via segue to ThirdViewController right from the IB) to the ThirdViewController.
i.e in MasterViewController ---> (tap barButtonItem) ----> SettingsViewControler ----> (tap uiButton) ---> ThirdViewController.
I have already amended the info.plist and 3D touch works fine and can call my action:
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
var shortcutDictionary = shortcutItem.userInfo;
let shortcutString1 = shortcutDictionary!["key1"] as! String
if (shortcutString1 == "value1") {
// how do i get from here to the settingsController??
}
}
EDIT:
already have tried:
let viewController = MasterViewController() viewController.settingsButton.sendActionsForControlEvents(.TouchUpInside)
which gives me an error:fatal error trying to unwrap an optional value!
although this exists in MasterViewController
@IBOutlet weak var settingsButton: UIButton!
This is the code I use for the shortcut....
func actionFromShortcut(sender: AnyObject!) {
let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.performSegueWithIdentifier("shotcutToSettings", sender: nil)
//some other stuff here.....
})
Also as per @MattLong's comment I have duplicated the segues to my controllers (one with and one without animation). That way the shortcut transition seems simultaneous when the action is called from the shortcut.
You will notice a delay of 0.1. It is to give the MasterViewController time to load cause whenever I tried to call the shortcut from cold (app not running) I would end up with the viewController I requested but there would be an empty MasterViewController to return to and hence crash....