Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. class CassiniViewController: UIViewController, UISplitViewControllerDelegate {
  2.  
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5.  
  6. // Do any additional setup after loading the view.
  7. }
  8.  
  9. override func didReceiveMemoryWarning() {
  10. super.didReceiveMemoryWarning()
  11. // Dispose of any resources that can be recreated.
  12. }
  13.  
  14.  
  15. //22
  16.  
  17. override func awakeFromNib() {
  18. super.awakeFromNib()
  19. self.splitViewController?.delegate = self
  20. }
  21. // MARK: - Navigation
  22.  
  23. // In a storyboard-based application, you will often want to do a little preparation before navigation
  24. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  25. // Get the new view controller using segue.destinationViewController.
  26. // Pass the selected object to the new view controller.
  27. //17
  28. if let url = DemoURL.NASA[segue.identifier ?? "" ] {
  29. //18.
  30. if let imageVC = (segue.destination.contents as? ImageViewController) {
  31. imageVC.imageURL = url
  32. imageVC.title = (sender as? UIButton)?.currentTitle
  33. }
  34. }
  35. }
  36.  
  37. //23
  38. func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
  39. if primaryViewController.contents == self {
  40. if let ivc = secondaryViewController.contents as? ImageViewController, ivc.imageURL == nil {
  41. return true
  42. }
  43. }
  44. return false
  45. }
  46.  
  47. }
  48.  
  49. //19.
  50. extension UIViewController {
  51. var contents: UIViewController {
  52. if let navcon = self as? UINavigationController {
  53. return navcon.visibleViewController ?? self
  54. } else {
  55. return self
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement