Created
April 30, 2017 10:49
-
-
Save helloworldsmart/ab7bbd652b891d97bee0c178bd12068c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CassiniViewController: UIViewController, UISplitViewControllerDelegate { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view. | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| //22 | |
| override func awakeFromNib() { | |
| super.awakeFromNib() | |
| self.splitViewController?.delegate = self | |
| } | |
| // MARK: - Navigation | |
| // In a storyboard-based application, you will often want to do a little preparation before navigation | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| // Get the new view controller using segue.destinationViewController. | |
| // Pass the selected object to the new view controller. | |
| //17 | |
| if let url = DemoURL.NASA[segue.identifier ?? "" ] { | |
| //18. | |
| if let imageVC = (segue.destination.contents as? ImageViewController) { | |
| imageVC.imageURL = url | |
| imageVC.title = (sender as? UIButton)?.currentTitle | |
| } | |
| } | |
| } | |
| //23 | |
| func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool { | |
| if primaryViewController.contents == self { | |
| if let ivc = secondaryViewController.contents as? ImageViewController, ivc.imageURL == nil { | |
| return true | |
| } | |
| } | |
| return false | |
| } | |
| } | |
| //19. | |
| extension UIViewController { | |
| var contents: UIViewController { | |
| if let navcon = self as? UINavigationController { | |
| return navcon.visibleViewController ?? self | |
| } else { | |
| return self | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment