Add contents to root of UINavigationController

On the main form I have a full screen "UINavigationController". The initial contents to show in the main form is a "home screen", which is a "UIViewController" in another unit (in a TFrame that I create manually).

I want the contents of the latter to be shown as the initial root view on the main form.

In the MainForm.Create I can call UINavigationController.PushViewController(UIViewController,false). However there are two problems:
1) I get an error: "external exception 434c4e47432b2b00" when I run the program.
2) This method is not setting the contents of the root view controller, but just pushing another ViewController on top of the root controller. So it shows a "Back" button in the navigation bar.

How do I set the TFrame.UIViewController as the root of the navigation controller? 
- or alternatively just move the contents of it.

Using Delphi 10 Seattle with iCL Mac runs XCode 7.1 and targeting iPad with iOS 9.1


Changing the root view controller is not possible. You will need to move the children of the viewcontroller on the frame by looping through them and changing the parent to the navigationcontroller

Kind Regards, 

Yes, that is what I have done so far. I simply set UIViewController.Parent := UINavigationController. That works fine, but I found that it uses more memory.

With XCode->Instruments->Allocations I can see that each allocated fullscreen UIView takes up 12 MB of memory (on a Retina iPad i.e. 2048x1536x32bit). Instruments describes them as "VM: UIViewEx(CALayer)"

When I have this code in MainForm.Create:
    UIViewController.Parent := UINavigationController
The Instruments->Allocations shows two persistent instances (described as "VM: UIViewEx(CALayer)" of 12 MB each = 24 MB memory.

However, when I have this code in MainForm.Create:
    UIViewController.Parent := UINavigationController;
    UINavigationController.PushViewController(UIViewController, false);
There is only one persistant instance = 12 MB memory.

That is the reason for my question in this thread. In my large application, Instruments shows 7 persistant fullscreen allocations of UIViewEx(CALayer) taking up 84 MB of memory, which is way to much on an older iPad.
Maybe I am misunderstanding something here, but I am basically just trying to reduce memory allocation. It is unclear for me what the actual problem is.

An interesting discovery in my attempt to reduce memory is: It seems to be the size of the view at create time that matters. If the UIViewController is small at design time then the allocated memory is also small, even if it is later Pushed on the NavigationController and becomes full screen.

Maybe the memory consumption I found is related to the Delphi/iCL wrapping of the objective-C objects?


The memory consumption could indeed be related to Delphi/iCL wrapping. To try to avoid unneccesary memory allocation you could simply store your objects inside a TLayout and then loop through the children and set the parent of them to the NavigationController instead (which already has a viewcontroller instance).

Kind Regards,