Iphone ios:以编程方式创建导航栏,但无法设置标题

Iphone ios:以编程方式创建导航栏,但无法设置标题,iphone,ios,navigation,uinavigationbar,Iphone,Ios,Navigation,Uinavigationbar,我在不使用xib文件的情况下以编程方式创建导航栏。 创建一个左侧按钮,文本为“left”,添加到导航栏,并将标题设置为“Demo” 代码: -(void) createNavBar:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options { self.navBarController = [[[UINavigationController alloc] init] autorelease]; nav

我在不使用xib文件的情况下以编程方式创建导航栏。 创建一个左侧按钮,文本为“left”,添加到导航栏,并将标题设置为“Demo”

代码:

-(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];
}
但是,程序可以成功设置navigationbar背景图像,显示左侧按钮,但无法设置标题。这么奇怪

补充:
我使用cordova框架来调用。而接口只能提供给cordova调用。 谢谢下面的答案,但我仍然无法解决我的问题

屏幕截图:(注意:显示左侧按钮但不显示标题)

设置

设置

请试试这个:

self.navigationItem.title=@"Your Title";
请试试这个:

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

您可以设置视图标题,它在导航栏上显示标题

self.title=@"My Navigation View";  
也可以在要显示的视图中设置navigationBarTitle

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

您可以设置视图标题,它在导航栏上显示标题

self.title=@"My Navigation View";  
也可以在要显示的视图中设置navigationBarTitle

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

请尝试以下代码段:

//nativeControls.hideLeftNavButton();

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

    nativeControls.showNavBar();
否则,请参阅本博客:

尝试以下代码片段:

//nativeControls.hideLeftNavButton();

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

    nativeControls.showNavBar();
否则,请参阅本博客:

我使用cordova框架来调用。而接口只能提供给cordova调用。谢谢你的回答,但我还是不能解决我的问题。谢谢你的回复,试试这个谢谢你的好意。是的,我使用NativeControl插件,但是我修改了一些东西。我以编程方式初始化视图,代码为“self.navBarController=[[[UINavigationController alloc]init]autorelease];”,无法设置标题。我给出此代码是为了了解xcode概念。其实我不知道这个插件,我也帮了你。我需要时间来研究这个插件。我使用cordova框架来调用它。而接口只能提供给cordova调用。谢谢你的回答,但我还是不能解决我的问题。谢谢你的回复,试试这个谢谢你的好意。是的,我使用NativeControl插件,但是我修改了一些东西。我以编程方式初始化视图,代码为“self.navBarController=[[[UINavigationController alloc]init]autorelease];”,无法设置标题。我给出此代码是为了了解xcode概念。其实我不知道这个插件,我也帮了你。我需要时间研究这个插件。可能重复的可能重复的