【发布时间】:2012-04-24 22:01:25
【问题描述】:
我正在制作一个 iPhone 应用程序,并希望在我的导航栏的 titleview 位置显示一个徽标。我创建了 UINavigationController 的子类,并在 viewDidLoad 中添加了以下行:
self.navigationBar.topItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"titlelogo.png"]];
(这对一行来说可能看起来很浪费,但我在多个地方使用它,出于各种原因我不想使用 [UINavigationBar 外观])
这适用于导航控制器的直接子级 - 我看到了徽标。但是,当我将 segue 推送到另一个视图时,即使它们(据我所知)是“相同”导航控制器的一部分,徽标也不会延续。
(供参考)-> MyNavigationController -> SomeViewController -> SomeOtherViewController
我也尝试过进入 SomeOtherViewController 的 viewDidLoad :
self.navigationController.navigationBar.topItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"titlelogo.png"]];
这仍然没有显示徽标。
经过一番摸索,我发现如果 1) 我在导航控制器的 viewDidLoad 中没有该行,并且 2) 我在 SomeOtherViewController 的 viewDidLoad 中确实有第二行,那么:
开始:查看 SomeViewController。没有标志。 Click to push segue:徽标现在出现在 SomeViewController 的栏上,然后消失。 我现在正在查看没有徽标的 SomeOtherViewController:。 点击返回:SomeViewController 的导航栏还有 logo。
显然我误解了导航控制器的工作原理。谁能告诉我如何解决这个问题?
【问题讨论】:
标签: iphone ios xcode navigationbar