0

In my tvOS app, I have an AVPlayerViewController, presented via a show segue, that shows an alert and unwinds to the previous view if no videos are found. I create an alert controller, present it, and call the unwind segue on the alert action handler. Everything appears to work as expected but I've found that the unwound view controller isn't being deallocated.

let noVideosAlertController = UIAlertController(title: "No Videos Configured", message: "No videos are configured for this bank. Log into the OEC and select Lobby Display to add videos to your playlist.", preferredStyle: .Alert)
let alertAction = UIAlertAction(title: "OK", style: .Default) { [weak self] (alert) in
    self?.performSegueWithIdentifier("unwindToConfig", sender: self!)
}

noVideosAlertController.addAction(alertAction)
presentViewController(noVideosAlertController, animated: true, completion: nil)

I've found that if I don't call the unwind and manually press the menu button to go back, it deallocates just fine so something about the unwind segue isn't allowing the player to be deallocated. I've also tried replacing the unwind segue with dismissViewControllerAnimated and it appears to dismiss the player but still no dealloc.

Andrew Cox
  • 13
  • 2
  • There is likely something wrong with your unwind segue. I tested your code with `self?.navigationController?.popViewControllerAnimated(true)` instead and `deinit` is called. You might consider calling that or `self?.navigationController?.popToRootViewControllerAnimated(true)` if either of those work for your situation. Otherwise describe how your unwind segue is set up. – beyowulf Jul 19 '16 at 12:47
  • I'm not using a navigation controller so `popToRootViewControllerAnimated` won't work. I set up the unwind with an IBAction in the config view controller I want to unwind to, an unwind segue identified as "unwindToConfig" in the AVPlayerViewController, and it's triggered by `performSegueWithIdentifier`. As a reference I used [this apple doc](https://developer.apple.com/library/ios/technotes/tn2298/_index.html) with some additional help from [this guide](https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/) to set it all up. – Andrew Cox Jul 19 '16 at 16:10
  • Why are you using a show segue if you're not using a `UINavigationController`? Are you using a `UISplitViewController`? Perhaps you could describe the structure of your app. – beyowulf Jul 19 '16 at 16:43
  • The app has a series of UIViewControllers that are presented on top of each other via Show segues. – Andrew Cox Jul 19 '16 at 16:51

1 Answers1

0

After testing this with a nearly empty file that just loads, shows the alert, and unwinds on the alert action handler, it deallocates just fine. I tracked this to the AVPlayerViewController's viewDidDisappear method that I was overriding to do some cleanup. Changing it to viewWillDisappear fixed my issue though I'm not sure why.

Andrew Cox
  • 13
  • 2