【问题标题】:NavigationBar titleView jump on viewWillAppearNavigationBar titleView 在 vi​​ewWillAppear 上跳转
【发布时间】:2016-04-08 23:20:08
【问题描述】:

我创建 NavTitleView.xib(在这个 xib 2 标签“TITLE”和“SUBTITLE”中添加)并为此 xib swift 文件创建。

然后我想用这个 xib 作为 navigationItem.titleView

在viewWillAppear中我写了这段代码

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
        let titleView = NSBundle.mainBundle().loadNibNamed("NavTitleView", owner: self, options: nil)[0] as! NavTitleView
        titleView.TitleLabel.text = "My beautiful title"
        titleView.SubtitleLabel.text = "My beautiful subtitle"
        self.navigationItem.titleView = titleView

}

一切都很好!但是当我的视图出现时 - 这个 NavTitleView 会从左侧跳到中心!我不明白为什么?如何解决?

【问题讨论】:

  • 将此代码移动到viewDidLoad,这样它只会被调用一次。
  • 将此代码移动到 viewDidLoad 不能解决问题!!如果我在 viewDidLoad 中移动此代码-标题视图将跳转一次!!!
  • @Dmitry 您正在实现自定义导航栏?
  • @Dmitry 你有没有找到任何解决方案,请告诉我。我也面临同样的问题。

标签: swift ios9 navigationbar uinavigationitem


【解决方案1】:

如果您设置了rightBarButtonItem,请尝试在viewWillAppear 中再次调用self.navigationItem.rightBarButtonItem = UIBarButton

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多