开发者

problem in UINavigation controller

开发者 https://www.devze.com 2023-02-25 01:15 出处:网络
hi to all i am trying to do a simple navigation based application.this is my code #import <UIKit/UIKit.h>

hi to all i am trying to do a simple navigation based application.this is my code

#import <UIKit/UIKit.h>
@class RootViewController;  
@interface jeeAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
    RootViewController *viewcontroller;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;  
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;     
@property (nonatomic, retain) IBOutlet RootViewController *viewcontroller;

@end   

.m file

#import "jeeAppDelegate.h"
#import "RootViewController.h"


@implementation jeeAppDelegate

@synthesize window;  

@synthesize navigationController;  




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];  
    [self.window addSubview:navigationControl开发者_开发百科ler.view];  
    [self.window makeKeyAndVisible];  

    return YES;
}

For this code i got "Application tried to push a nil view controller on target <UINavigationController: 0x4b4f5c0>." thanks in advance..


This is fairly simple - at no point have you initialised the view controller that you're attempting to push onto the navigation stack.

i.e.: Before you call..

navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];  

...you need to ensure that viewcontroller actually exists, in the sense that you need to alloc and init it.

For example:

// Create our main menu view controller
MainMenuViewController *mainMenuVC = [[MainMenuViewController alloc] init];

// Create our navigational controller and init it with the main menu view controller
navController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];
[mainMenuVC release];

In the above mainMenuVC is a custom view controller that I've created.

Also, please note that once you've added your view controller to the navigation controller, you can release it as the navigation controller with retain it.

0

精彩评论

暂无评论...
验证码 换一张
取 消