设置在Interface Builder中创建的导航栏的标题 [英] Set the title of Navigation Bar created in Interface Builder

查看:70
本文介绍了设置在Interface Builder中创建的导航栏的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模态视图控制器,其视图来自XIB.我希望它具有与基于导航的应用程序其余部分相同的外观,但是并不是将视图强制推送到导航堆栈中,而是以模态显示.我将UINavigationBar拖入其中并使其成为插座,但是它没有title属性可供设置.我有两个字段可以显示此模式视图,并且我希望标题集根据创建模式视图的方式而有所不同.

I have a modal view controller whose view comes from a XIB. I want it to have the same look and feel as the rest of my navigation based app, but it's not a view that's pushed to the navigation stack, it's presented modally. I dragged a UINavigationBar in and made it an outlet, but it doesn't have a title property to set. I have two fields that can bring up this modal view, and I want the title set differently depending on which one creates the modal view.

推荐答案

UINavigationBar管理UINavigationItem的堆栈就像UINavigationController管理器管理UIViewController的堆栈一样.要设置直接可见的图像,应使用pushNavigationItem:animated:setItems:animated:并使用您希望条形反射的视图控制器的navigationItem.

UINavigationBar's manage a stack of UINavigationItems much like a UINavigationController manager a stack of UIViewControllers. To set what is visible directly, you should use either pushNavigationItem:animated: or setItems:animated: using the navigationItem of the view controller you want the bar to reflect.

例如:

self.navigationItem.title = @"A custom title";
[self.navigationBar pushNavigationItem:self.navigationItem animated:NO];

上面的代码中具有属性navigationBar,该属性引用了独立的导航栏.

The above code where you have a property navigationBar which references the stand-alone navigation bar.

如果您不想自己管理它,则可以按照mplappert的建议进行操作,并将视图控制器(没有独立的UINavigationBar)嵌套在UINavigationController中,然后以模态形式显示导航控制器,而不是视图控制器.

If you don't want to manage it yourself, you can do as mplappert suggested and nest your view controller (without a stand-alone UINavigationBar) in a UINavigationController and present the navigation controller modally instead of your view controller.

这篇关于设置在Interface Builder中创建的导航栏的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆