CoronaViewController
The CoronaViewController
is a subclass of the UIViewController
/GLKViewController
class. If you’re building a multi-view app, you can programmatically make the CoronaView
a child view. Typically, you instantiate a CoronaViewController
when it’s not the root controller, for example when the CoronaViewController
is a child of another controller.
When creating a CoronaViewController
as a child controller, you must override the viewDidLoad
method of the parent controller via the following steps:
Instantiate the CoronaViewController
and ensure that it exists for the lifetime of the CoronaView
. In the example below, coronaController
is a property of the parent controller that implicitly retains upon assignment.
Add the CoronaViewController
as a child controller of the parent. This ensures that notifications from the parent controller are propagated to the CoronaViewController
, for example when the parent view appears or disappears.
Size the CoronaView
. When this view is loaded programmatically, it defaults to the size of the screen.
Add the CoronaView
as a child view of the parent controller’s view.
Tell CoronaView
which main.lua
file to run. In the example below, we run the main.lua
that is present at the root of the .app
bundle. However, you can choose an arbitrary main.lua
file by calling runWithPath:parameters:
instead.
// This method belongs to the parent UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.coronaController = [[[CoronaViewController alloc] init] autorelease]; // (Step 1)
[self addChildViewController:self.coronaController]; // (Step 2)
CoronaView *coronaView = (CoronaView *)self.coronaController.view;
// Same size as parent view
coronaView.frame = self.view.frame; // (Step 3)
[self.view addSubview:coronaView]; // (Step 4)
[coronaView run]; // (Step 5)
}