ios 在 xcode 中设置导航栏的标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10124574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
setting Title for navigation bar in xcode
提问by Anish
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.
但是当我在 addViewController 类中添加 self.title = @"Title" 时。它没有显示。
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..
任何的想法..
采纳答案by Alexander
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.
然后在方法中设置类的title
属性。addViewController
viewWillAppear
回答by o15a3d4l11s2
You should assign the title to the addView
like addView.title = @"Title";
您应该将标题分配给addView
喜欢addView.title = @"Title";
Another way to do it is self.navigationItem.title = @"Title";
另一种方法是 self.navigationItem.title = @"Title";
回答by Marouene Tekaya
In the viewController class:
[self setTitle:@"title"];
or self.title=@"title";
在 viewController 类中:
[self setTitle:@"title"];
或self.title=@"title";
回答by DogCoffee
This seem to work fine for me
这对我来说似乎很好用
self.navigationController.navigationBar.topItem.title = @"Title";
回答by Felix Lamouroux
Your navigation controller isn't correctly setup:
您的导航控制器设置不正确:
UINavigationController *addViewControl = [[UINavigationController alloc]initWithRootViewController:addView];
// delete this line: [addViewControl.view addSubview:addView.view];
回答by Daniel Lima
This is working on an app that I'm creating:
这是我正在创建的应用程序:
[self.navigationItem setTitle:@"title here"];