Advertisement
Don_Mag

Untitled

Aug 19th, 2021
1,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.23 KB | None | 0 0
  1. /*
  2. Create a new project...
  3.  
  4. - Embed the default View Controller in a Navigation Controller
  5. - add two buttons: "Push" and "Present"
  6.  
  7. Connect the buttons to these actions:
  8. */
  9.  
  10. class ViewController: UIViewController {
  11.    
  12.     @IBAction func doPush(_ sender: Any) {
  13.         if let vc = storyboard?.instantiateViewController(withIdentifier: "ProfileViewController") {
  14.             navigationController?.pushViewController(vc, animated: true)
  15.         }
  16.     }
  17.    
  18.     @IBAction func doPresent(_ sender: Any) {
  19.         if let vc = storyboard?.instantiateViewController(withIdentifier: "ProfileViewController") {
  20.             present(vc, animated: true, completion: nil)
  21.         }
  22.     }
  23.  
  24. }
  25.  
  26. /*
  27. - add another View Controller (ProfileViewController)
  28. - add one button: "Done"
  29.  
  30. Connect the button to this action:
  31. */
  32.  
  33. class ProfileViewController: UIViewController {
  34.    
  35.     @IBAction func gotTap(_ sender: Any) {
  36.         if let pvc = presentingViewController {
  37.             pvc.dismiss(animated: true, completion: nil)
  38.         } else {
  39.             navigationController?.popViewController(animated: true)
  40.         }
  41.     }
  42.    
  43.     deinit {
  44.         print("ProfileViewController deinit")
  45.     }
  46.  
  47. }
  48.  
  49. /*
  50. Run the app...
  51.  
  52. See if you get "ProfileViewController deinit" as expected.
  53.  
  54. Check the Memory Graph to see if it looks the same as your app.
  55. */
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement