导航栏标题未设置 iPhone

发布于 2024-09-26 14:49:53 字数 947 浏览 1 评论 0原文

在我的应用程序中,我呈现了一个模态视图控制器,如下所示,我无法更改导航栏的标题或其任何属性。

fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:@"fullListTopCompanies" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;
[submit release];


[self presentModalViewController:cntrol animated:YES];
[cntrol release];

我尝试实例化应用程序委托并将其导航控制器分配给本地导航控制器实例,但没有用。

不知何故,导航控制器无法访问。无法使用“self.navigationitem”访问它。每当我将 modalviewcontroller 与导航控制器一起呈现时,该导航都会位于实际导航控制器的下方。

In my app, I'm presenting a modalviewcontroller as follows and I'm not able to change the navigationbar's title or any of its properties for that matter.

fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:@"fullListTopCompanies" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;
[submit release];


[self presentModalViewController:cntrol animated:YES];
[cntrol release];

I tried instantiating application delegate and assigning its navigationcontroller to local navigationcontroller instance but no use.

Somehow that navigationcontroller is not accessible. It can't be accessed by using "self.navigationitem". Whenever I present modalviewcontroller with the navigationcontroller, this navigation comes below the actual navigationcontroller.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄暮涼年 2024-10-03 14:49:53

例如,如果您尝试为名为“ABCViewController”的 ViewController 设置导航栏标题,则

添加self.Title = @"";

viewWillAppear 方法中 ABCViewController 并尝试重建并运行。

希望这有帮助。 :)

For Example, if you are trying to set title of navigation bar for the ViewController called "ABCViewController", then add

self.Title = @"";

in viewWillAppear Method of the ABCViewController and try to rebuild and Run.

Hope this helps. :)

胡渣熟男 2024-10-03 14:49:53

每当我将 modalviewcontroller 与导航控制器一起呈现时,该导航都会位于实际导航控制器下方。

这个问题是因为在 self 上调用 presentModalViewController: ,您应该在 self.navigationController 上调用它,这样导航控制器就不会显示在另一个控制器的下方。

至于为什么不能设置navigationController的属性,我不知道。对我来说看起来不错。但我预计这是因为您在 nib-loader 调用 viewDidLoad 之前设置了属性。我想我自己很久以前就遇到过这样的问题。

您应该在 UIViewController 子类的 viewDidLoad 方法中设置标题等,我想您的担忧将会结束。

Whenever I present modalviewcontroller with the navigationcontroller, this navigation comes below the actual navigationcontroller.

That problem is because calling presentModalViewController: on self, you should call it on self.navigationController that way the navigation controller won't be shown below the other one.

As to why you can't set the navigationController's properties, I don't know. It looks Ok to me. But I expect it is because you are setting the properties before viewDidLoad is called by the nib-loader. I think I remember having problems like this myself a long time ago.

You should set the title etc. in the UIViewController subclass's viewDidLoad method and I think you worries will be over.

情徒 2024-10-03 14:49:53

我使用 xcode 模板创建了一个简单的基于视图的应用程序,然后我添加了您的代码,它对我有用...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.

// Add the view controller's view to the window and display.

TestViewController *fullListTopCompaniesInstance = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;

[window addSubview:viewController.view];
[window makeKeyAndVisible];

[viewController presentModalViewController:cntrol animated:YES];

[cntrol release];
[submit release];

return YES;

}

I've created a simple view based app with xcode template, then i've added your code and it's working for me...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.

// Add the view controller's view to the window and display.

TestViewController *fullListTopCompaniesInstance = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;

[window addSubview:viewController.view];
[window makeKeyAndVisible];

[viewController presentModalViewController:cntrol animated:YES];

[cntrol release];
[submit release];

return YES;

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文