2011-07-20 17 views
0

我有下面的代碼,但不顯示UINavigationBar的不能得出UINavigationBar的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [self.navigationController setDelegate:self]; 
    FeedsController *feedsController = [[[FeedsController alloc] init] autorelease]; 

    self.window.rootViewController = feedsController; 
    self.reload = 1; 

    #if !TARGET_IPHONE_SIMULATOR 
     [application registerForRemoteNotificationTypes: 
     UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 
    #endif 

    application.applicationIconBadgeNumber = 0; 
    //self.textView.text = [launchOptions description]; 


    [_window addSubview:navigationController.view]; 
    //[_window setRootViewController:feedsController]; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

誰可以幫我?

+0

這是一個基於導航的應用程序或基於窗口或視圖的應用程序嗎? – Ishu

+0

我沒有看到你在任何地方初始化'navigationController'?這可能是零。 – Pripyat

回答

0

你可以嘗試下面的代碼,它對我來說工作正常。

UINavigationBar *navBar = [[[UINavigationBar alloc] initWithFrame: 
          CGRectMake(0,0,320,44)] autorelease]; 
navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 


UINavigationItem *NavTitle = [[[UINavigationItem alloc] initWithTitle:@""] autorelease]; 
[navBar pushNavigationItem:NavTitle animated:YES]; 
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; 
label.backgroundColor = [UIColor clearColor]; 
label.font = [UIFont boldSystemFontOfSize:20.0]; 
label.textAlignment = UITextAlignmentCenter; 
label.textColor = KTITLECOLOR; 
label.text = LOCALSTR(@"s_sms"); 
CGSize labelSize = [label.text sizeWithFont:label.font]; 
label.frame = CGRectMake((width - labelSize.width)/2, (kTitleBarHeight - labelSize.height)/2, labelSize.width, labelSize.height); 
[label sizeToFit]; 
[navBar addSubview:label]; 

UIBarButtonItem *gobackBtn =[[[UIBarButtonItem alloc] initWithTitle:LOCALSTR(@"goback") style:UIBarButtonItemStylePlain target:self action:@selector(goBack)] autorelease]; 
navBar.topItem.leftBarButtonItem = gobackBtn; 
[self.view addSubview:navBar];