views:

618

answers:

5

Hi,

I am having difficulty geting a very simple view to display. This view has a custom view controller that is manages by a switching view controller. The XIB has one UIViewController component on it with its Image property set. The view controller is as follows:

InstructionsViewController.h

#import <UIKit/UIKit.h>

@interface InstructionsViewController : UIViewController {

}

@end

InstructionsViewController.m

#import "InstructionsViewController.h"

@implementation InstructionsViewController



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (void)dealloc {
    [super dealloc];
}


@end

I have also set the class property for the XIB's File's Owner to InstructionsViewController, and Ctrl+Dragged File's Owner to the View icon and selected View from the popup menu.

The code to display the view is:

- (void) showInstructions
{
    //Lazy load the instruction view.
    if (self.instructionsViewController == nil)
    {
     InstructionsViewController *viewController = [[InstructionsViewController alloc]
               initWithNibName:@"InstructionsView" 
               bundle:nil];
     self.instructionsViewController = viewController;
     [viewController release];
    }

    [self.view insertSubview:viewController.view atIndex:0];
}

My view controller that animates different views when they are switched, has no problems loading and displaying three other views. It just doesn't like this one.

I'm sure I've missed something simple, but for the life of me I can't get it to work for some reason. Does anyone have any pointers?

Thanks,

Steve

A: 

Not even really sure how this is compiling. You are inserting the subview outside of your nil check, where viewController is out of scope.

You probably want to do

[self.view insertSubview:self.instructionsViewController.view atIndex:0];

bpapa
A: 

It was a typo on my part. The actual code is the same as what you described. Unfortunately, it doesn't work.

Any help is appreciated.

Steve

A: 

Have you verified that showInstructions is being called by setting a breakpoint there? One other thing to check is that you are inserting the Instructions view at the bottom of your z-order, so it will be behind all other items. Try using:

[self.view addSubview:self.instructionsViewController.view];

This will add it to the top of the z-order. If that doesn't work, also try:

[self.view setNeedsLayout];

and/or:

[self.instructionsViewController.view setNeedsLayout];
Jason
A: 

Jason,

Thanks for the constructive response. Yes, I have set the breakpoint and made sure the code was getting called. I also previously tried the code you described above, with no luck. I think the problem lies in the NIB. As a test, I took this code which works, and replaced "MenuView" with "InstructionsView"and the screen still shows blank. When I replace "MenuView" with any other view, other than "InstructionsView" the view renders properly.

- (void) showMenu 
{
    //Lazy load the menu view.
    if (self.menuViewController == nil)
    {
        MenuViewController *viewController = [[MenuViewController alloc]
            initWithNibName:@"MenuView"
            bundle:nil];

        self.menuViewController = viewController;
        [viewController release];
    }

    //Show the menu with no flourish.
    [self.view insertSubview:menuViewController.view atIndex:0]; 
}

In the InstructionsView NIB, I have the Class set to InstructionsViewController and the view's outlet is set to File's Owner.

I've even gone so far as to delete and re-create the InstructionsView NIB file. I'm stumped.

Any more assistance is greatly appreciated.

Thanks,

Steve

Steve
So I've been digging and it seems that the problem is with the PNG file that I specify in the View's Image View. When I specify the Instructions.png, the screen goes blank. But if I specify ANY other PNG in the project, the Instructions screen renders properly. When I switch the image back in INterface Builder, the screen goes blank again. It's weird because the ONG is basically a copy of other PNG files that work. Any thoughts?
Steve
A: 

Ok, I've finally solved it!

The problem was something in XCode or Interface Builder was not agreeing with the PNG file I specified for the Image View control in IB. I tried re-naming, and re-specifying, etc. to no avail.

I finally had to delete the graphic and re-copy it from it's source location. Then I re-specified it in Image View, build and ran. Now it works.

Everything is good in the world again.

Thanks to those who took the time to read and offer help. I appreciate it very much!

Steve

Steve