explorer
explorer

Reputation: 449

ios : create NavigationBar programmatically, but cannot set the title

I create an NavigationBar programmaticlly without using xib file. And create one left button with text "left", added to the navigationBar, and set the title to "Demo".

code :

-(void) createNavBar:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options
{

    self.navBarController = [[[UINavigationController alloc] init] autorelease];
    navBar = [navBarController navigationBar];
    navBarController.navigationBar.bounds = CGRectMake(0, 0, 320, navBarHeight);
    [navBarController.navigationBar  setBackgroundImage:[[UIImage imageNamed:@"www/images/ios_hd_bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 2, 0)]
     forBarMetrics:UIBarMetricsDefault];



    [navBarController view];

    navBarController.navigationItem.title = @"title";

    [navBarController.view setFrame:navBarController.navigationBar.bounds];

    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button = [self renderNavBarTextBtn:@"left" withButton:button direction:@"left"];
    [navBar addSubview:button];

    [[[self webView] superview] addSubview: navBarController.view];
}

however, the program can successfully set the navigationbar background image, show the left button, but cannot set the title. so strange?

complements: I use cordova framework to invoke . and The inteface just be provided to cordova invoke. Thanks for answers below, but I still can't solve my problem.

ScreenShot: (Note: showing the left button but not showing the title)

enter image description here

Upvotes: 0

Views: 8489

Answers (5)

amit rajput
amit rajput

Reputation: 18

 UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = _backButton;

    self.navigationItem.title=@"Demo";
    [_backButton release], 
    [_backButton = nil];

Upvotes: 4

Vikas S Singh
Vikas S Singh

Reputation: 1766

Try this code snippet :

//nativeControls.hideLeftNavButton();

    nativeControls.setupRightNavButton(
        "About",
        "",
        "onRightNavButton"
    );

    nativeControls.showNavBar();

otherwise refer to this blog : http://zsprawl.com/iOS/2012/05/navigation-bar-with-nativecontrols-in-cordova/

Upvotes: 0

Rajneesh071
Rajneesh071

Reputation: 31091

You can set your view title, which show title on navigation bar

self.title=@"My Navigation View";  

Or you can set navigationBarTitle in the view where you want to show

self.navigationItem.title=@"My Navigation";

Upvotes: 0

jorik
jorik

Reputation: 655

Please try this:

self.navigationItem.title=@"Your Title";

Upvotes: 1

AppleDelegate
AppleDelegate

Reputation: 4249

Set

navBar.title =@"Your title";

Upvotes: 0

Related Questions