0

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

explorer
  • 449
  • 2
  • 10
  • 19
  • possible duplicate of [Adding back button to navigation bar](http://stackoverflow.com/questions/2846539/adding-back-button-to-navigation-bar) – Alex K Oct 17 '12 at 06:55

5 Answers5

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

    self.navigationItem.title=@"Demo";
    [_backButton release], 
    [_backButton = nil];
amit rajput
  • 18
  • 12
  • 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. – explorer Sep 20 '12 at 12:58
  • Thanks for reply u try this one http://zsprawl.com/iOS/2012/05/navigation-bar-with-nativecontrols-in-cordova/ – amit rajput Sep 20 '12 at 13:22
  • thanks for you kind. yes, I use the NativeControls plugin, but I modify something. I init the view programmatically, with the code "self.navBarController = [[[UINavigationController alloc] init] autorelease];", and can not set the title. – explorer Sep 21 '12 at 00:47
  • I give this code for knowing the xcode concept. Actually i not knowing about this plugin than also i helped you. I need time for studying about this plugin. – amit rajput Sep 21 '12 at 04:14
1

Please try this:

self.navigationItem.title=@"Your Title";
J. Steen
  • 15,470
  • 15
  • 56
  • 63
jorik
  • 645
  • 7
  • 15
0

Set

navBar.title =@"Your title";
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27
0

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";
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
0

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/

Vikas S Singh
  • 1,748
  • 1
  • 14
  • 29