Question

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

Was it helpful?

Solution 4

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

OTHER TIPS

I just had the same thing. Ended up deleting the UIImageView, placing a new one then relinked and it worked. Seems like some corruption somewhere.

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];

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top