无法绘制 UI 网络栏



我有以下代码,但没有显示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;
}

谁能帮我?

你可以试试下面的代码,它对我来说很好。

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

最新更新