[英]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. 但是当我在addViewController类中添加self.title = @“Title”时。 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";
您应该将标题分配给
addView
例如addView.title = @"Title";
Another way to do it is self.navigationItem.title = @"Title";
另一种方法是
self.navigationItem.title = @"Title";
In the viewController class: [self setTitle:@"title"];
在viewController类中:
[self setTitle:@"title"];
or self.title=@"title";
或者
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. 然后在
viewWillAppear
方法中设置addViewController
类的title
属性。
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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.