Detect when UIViewController was fired by remote menu button in tvOS

I am working on an Apple TV (tvOS) application where the controller of the first view opens the second view controller with a direct jump . When I select a parameter on the second view controller, it performs the unwind operation on the first view controller.

My problem is that when I press the remote menu button, the moderator of the second view mode is automatically turned off , and I see no way to perform an action on the first view controller or to receive a notification.

How can I detect when a controller opened through segue was disabled by a remote menu button?

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ First View β”‚ β”Œβ”€β”€β”€β”€β”€β” β”‚ Modal View β”œβ”€β”€β” β”‚ Controller β”œβ”€β”€β”€β”€β”€segueβ”œβ”€β”€β”€β”€β–Ά Controller β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Modal Auto β”‚ β”‚ Menu β”‚ β”‚ Action ?? ◀─── Dismiss ◀──────│Button β”‚β—€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜ 
+6
source share
2 answers

I believe that this is what you are trying to accomplish.

 // Put this in your FirstViewController @IBAction func returnToFirstViewController(segue:UIStoryboardSegue) { print("This is called after modal is dismissed by menu button on Siri Remote") } // Put this in your SecondViewController override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleMenuPress:")) tapRecognizer.allowedPressTypes = [UIPressType.Menu.rawValue] view.addGestureRecognizer(tapRecognizer) } func handleMenuPress(recognizer: UITapGestureRecognizer) { self.performSegueWithIdentifier("YourUnwindSegueIdentifier", sender: nil) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "YourUnwindSegueIdentifier" { // do any cleanup activities here if you need } } 

Now you need to do some storyboards. Go to your SecondViewController and ctrl-drag from your controller icon to the Exit icon, and you will see the following:

enter image description here

Select the method to connect it to, and then you will see the Unwind Segue in your SecondViewController in the storyboard. Check this identifier name "YourUnwindSegueIdentifier" (so my sample code will work - or use whatever name you want). Build and run, and this should help you with what you need.

+1
source

First view controller:

 @IBAction func modalDismissed(segue: UIStoryboardSegue) { print("Modal dismissed") } 

Modal Controller:

 override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) { for item in presses { if item.type == .Menu { self.performSegueWithIdentifier("dismissModal", sender: nil) } } super.pressesBegan(presses, withEvent: event) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "dismissModal" { print("Modal Dismiss") } } 

Create a segue output on a modular view controller named "rejectModal" enter image description here

0
source

All Articles