Don_Mag icon

Untitled

Don_Mag | PRO | 08/19/21 02:56:07 PM UTC | 0 ⭐ | 2385 👁️ | Never ⏰ | []
Swift |

1.23 KB

|

None

|

0 👍

/

0 👎

/*
Create a new project...
 
- Embed the default View Controller in a Navigation Controller
- add two buttons: "Push" and "Present"
 
Connect the buttons to these actions:
*/
 
class ViewController: UIViewController {
    
    @IBAction func doPush(_ sender: Any) {
        if let vc = storyboard?.instantiateViewController(withIdentifier: "ProfileViewController") {
            navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func doPresent(_ sender: Any) {
        if let vc = storyboard?.instantiateViewController(withIdentifier: "ProfileViewController") {
            present(vc, animated: true, completion: nil)
        }
    }
 
}
 
/*
- add another View Controller (ProfileViewController)
- add one button: "Done"
 
Connect the button to this action:
*/
 
class ProfileViewController: UIViewController {
    
    @IBAction func gotTap(_ sender: Any) {
        if let pvc = presentingViewController {
            pvc.dismiss(animated: true, completion: nil)
        } else {
            navigationController?.popViewController(animated: true)
        }
    }
    
    deinit {
        print("ProfileViewController deinit")
    }
 
}
 
/*
Run the app... 
 
See if you get "ProfileViewController deinit" as expected. 
 
Check the Memory Graph to see if it looks the same as your app.
*/
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎