如何为模态视图控制器设置标题栏标题?

时间:2011-07-21 08:57:38

标签: iphone objective-c cocoa-touch uiviewcontroller

self.title = @"My View";

当我的视图以模态呈现时不起作用。

3 个答案:

答案 0 :(得分:6)

您必须编写以下代码才能呈现modalView控制器..

yourModelController =[[Yourmodelcontroller alloc]init];

UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController: yourModelController];

[[self navigationController] presentModalViewController:controller animated:YES];
[controller release];

然后在viewDidLoad - 方法中你需要写

self.title =@"My View";

它肯定会奏效。希望它会对你有所帮助。

答案 1 :(得分:0)

请尝试这个:

self.title = NSLocalizedString(@"My View", @"Comment goes here");

答案 2 :(得分:0)

您可以在 ViewDidLoad()中使用 UINavigationItem 属性来设置导航栏的标题。

Swift Code:

self.navigationItem.title = "Bar Title"