I have a view whose controller is being instantiated (NSLog says so), but the view doesn’t show up. If I load it as a modal view it appears, but not if I allocate it.
I have this structure (MenuView is the view that doesn’t appear):
// ViewController.h
#import "MenuViewController.h"
@class MenuViewController;
@interface ViewController : UIViewController<ASIHTTPRequestDelegate>{
...
IBOutlet MenuViewController *menuView;
}
...
@property(nonatomic, retain) MenuViewController *menuView;
@end
// ViewController.m
#import "MenuViewController.h"
@implementation ViewController
@synthesize menuView;
- (void)loadMenu{
// THIS WORKS
// [self presentModalViewController:menuView animated:YES];
// THIS DOESN'T (VIEWCONTROLLER IS INSTANTIATED BUT VIEW DOESN'T APPEAR
menuView = [[[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil] autorelease];
[self.navigationController pushViewController:menuView animated:YES];
}
Some ideas:
Try using self.menuView when assigning:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];Also, probably shouldn’t autorelease a
property. Release it indeallocand set it tonilinviewDidUnload.Make sure that
self (ViewController)has anavigationController. WasViewControllerpushed/presented by anavigationController?Is
- (void)loadMenu{being called from the MainThread? Check with[NSThread mainThread]Check out some tutorials/examples:
Adding a Navigation Controller by Hand
NavigationController Application in iPhone
Tutorial: Introducing UINavigationController Part 1
iPhone View Switching Tutorial