Reputation: 1049
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];
}
Upvotes: 3
Views: 2011
Reputation: 52728
Try using self.menuView when assigning:
self.menuView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:Nil];
Also, probably shouldn't autorelease a property
. Release it in dealloc
and set it to nil
in viewDidUnload
.
Make sure that self (ViewController)
has a navigationController
. Was ViewController
pushed/presented by a navigationController
?
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
Upvotes: 2