简体   繁体   中英

setting Title for navigation bar in xcode

I have created a navigation controller programmatically,

        //Creating AddViewController Object
        addViewController *addView = [[addViewController alloc]init];
        UINavigationController *addViewControl = [[UINavigationController alloc]init];

        [addViewControl.view addSubview:addView.view];

        [self presentModalViewController:addViewControl animated:YES];

But when i add self.title = @"Title" in addViewController class. it is not displaying.

i tried with the following,

self.navigationItem.title = @"Title";

self.navigationController.navigationBar.topItem.title = @"Title";

But it's not displaying Title.

I think it is possible to do with setting a label. but the above one is direct method.

Any Idea..

You should assign the title to the addView like addView.title = @"Title";

Another way to do it is self.navigationItem.title = @"Title";

In the viewController class: [self setTitle:@"title"]; or self.title=@"title";

这对我来说似乎很好

self.navigationController.navigationBar.topItem.title = @"Title";

Try initializing your navigation controller this way:

UINavigationController *addViewControl = [[UINavigationController alloc] initWithRootViewController:addView];
[self presentModalViewController:addViewControl animated:YES];
//[addView release];
//[addViewControl release]; // uncomment these two lines if not using ARC

And then set the title property of your addViewController class in the viewWillAppear method.

Your navigation controller isn't correctly setup:

UINavigationController *addViewControl = [[UINavigationController alloc]initWithRootViewController:addView];
// delete this line: [addViewControl.view addSubview:addView.view];

这正在我正在创建的应用程序:

[self.navigationItem setTitle:@"title here"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM