Hi Matt,
I know what you mean. Sometimes there are days where
you do not even solve the easiest thing.
But in this case I can help you out. As far as I remember
it was not sufficient to have a UIViewController declared
in your application delegate or whereever you use the controller.
I decided to provide a class header and implementation file separately
for each xib/nib file I want to use in an isgl3d project.
Your app would contain the three files at least:
YourNibView.nib
YourNibViewController.h
YourNibViewController.mm
In your application delegate you can then allocate the controller like
this:
- (void) applicationDidFinishLaunching:(UIApplication*)application {
...
self.yourNibViewController = [[YourNibViewController alloc]
initWithNibName:@"YourNibView" bundle:nil];
// Create the UIWindow
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
bounds]];
[_window addSubview:yourNibViewController.view]; // here it is
{
// just to keep it simple - could be done later or put in a separate
method
[Isgl3dDirector sharedInstance].backgroundColorString =
@"333333ff";
[Isgl3dDirector sharedInstance].deviceOrientation =
Isgl3dOrientationLandscapeRight;
_viewController = [[Isgl3dViewController alloc] initWithNibName:nil
bundle:nil];
_viewController.wantsFullScreenLayout = YES;
Isgl3dEAGLView * glView = [Isgl3dEAGLView viewWithFrameForES1:
[_window bounds]];
// Set view in director
[Isgl3dDirector sharedInstance].openGLView = glView;
[Isgl3dDirector sharedInstance].autoRotationStrategy =
Isgl3dAutoRotationByUIViewController;
[Isgl3dDirector sharedInstance].allowedAutoRotations =
Isgl3dAllowedAutoRotationsLandscapeOnly;
// Set the animation frame rate
[[Isgl3dDirector sharedInstance] setAnimationInterval:1.0/60];
_viewController.view = glView;
}
[_window makeKeyAndVisible];
// just to keep it simple - could be done later or put in a separate
method like above
[[Isgl3dDirector sharedInstance] run];
}
You will see your xib/nib view integrated in the isgl3d project now.
Ok, what's next.
Imagine you have a HelloWorldView class that derives from
Isgl3dBasic3DView and contains
your scene. I would not assign it to the UIWindow instance in the
method above. I would
provide a method to put it into the main window whenever it is
necessary. For this simple
usage you can use a switchViews method in your application delegate as
follows:
- (void) switchViews
{
if (_viewController.view.superview == nil) {
// add the view to the window as subview
[_window addSubview:_viewController.view];
[_window bringSubviewToFront:_viewController.view];
[yourNibViewController.view removeFromSuperview];
if (!_helloWorldView)
_helloWorldView = [HelloWorldView view];
} else
{
[_window addSubview:yourNibViewController.view];
[_window bringSubviewToFront:yourNibViewController.view];
[_viewController.view removeFromSuperview];
}
}
And to complete this simple example you invoke the switchViews method
from an IBAction
method in your controller class YourNibViewController.
- (IBAction)buttonPressed
{
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication
sharedApplication] delegate];
if (appDelegate) {
[appDelegate switchViews];
}
}
I hope that this small and simple example can help to solve your
problem.
I also agree with you that such examples belong to the isgl3d bundle
to show how the usage of
xib/nib files can look like.
Rudi