Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using view controllers efficiently


iOS is very strict about memory usage. If an app uses too much memory, iOS will issue memory warnings. If we do not respond to these memory warnings accordingly by releasing resources that are not needed, it is very likely that iOS will terminate the app.

Getting ready

Let's see what we can do to avoid this situation. Create a new project in Xamarin Studio and name it EfficientControllerApp.

How to do it…

Perform the following steps to complete this recipe:

  1. Add a view controller to the project and name it MainController.

  2. Enter the following code in the DidReceiveMemoryWarning method of the MainController class:

    Console.WriteLine("Main controller received memory warning!");
  3. Make the controller the root view controller of the app in AppDelegate.cs as follows:

    MainController mainController = new MainController();
    window.RootViewController = mainController;
  4. Compile and run the app on the simulator.

  5. With iOS Simulator window active, navigate to Hardware | Simulate Memory...