popUpZendo / PopUpZendoTimer

0 stars 0 forks source link

Develop segue strategy and dismissing view controllers #4

Open ShinboJosephHall opened 4 years ago

ShinboJosephHall commented 4 years ago

Background

Most app segues are simple storyboard segues, which were used because they were easy and I didn't know the ramifications of using different kinds of programmatic segues. It appears that the result is that we are using a ton of resources and things are not being refreshed.

To Do

cupnoodle commented 4 years ago

I have played around with the app and realized the view controllers keep added to the top of the stack when I navigate around, they are not dismissed when I navigate back to previous view controller. As view controllers are not dismissed, they stay in the memory (RAM) of phone, and when a certain limit of memory is exceeded, iOS proceed to kill the app as it uses too much memory.

Here's a demo video where navigate between TimerViewController and SettingsViewController, and notice that SettingsViewController are not dismissed (removed from memory) when I go back to TimerViewController.

stacks.mp4.zip

You can use the 3d stack icon to inspect the current stack of view controllers when the app is running, you can drag to inspect the layers of view controller.

I recommend removing the segue for the close button in SettingsViewController, and add a IBAction for the close button in (ie. link the close button to view controller), and execute the dismiss code as below :

@IBAction func closeButton(_ sender: Any) {
    // self.presentingViewController is the previous view controller which segues to the current view controller
    // if there is a previous view controller
    if(self.presentingViewController != nil) {
       // dismiss current view controller (ie. settings view controller), which remove it from memory, and go back to previous view controller (ie. timer view controller)
        self.dismiss(animated: true, completion: nil)
    }
}

You can use the code above to dismiss view controller instead of using segue to go back to previous view controller.