推送弹出导航堆栈

时间:2017-11-15 17:10:32

标签: ios uinavigationcontroller uibarbuttonitem

我有一个UIBarButtonItem,“完成” - 在ViewController A的故事板IB中创建。

ViewController A是导航堆栈的根视图控制器。

如果我将视图控制器B推入导航堆栈然后再次弹出。完成按钮的字体粗细更改。

Start Scenario - A B pushed onto stack B popped from the stack

完成按钮的字体颜色应用于A.viewWillAppear(..),看起来非常像

doneButton.tintColor = [CMPThemes navigationBarItemColour]; // it's a blue
  • 我从应用程序中剥离了所有外观代理代码(因为那里 是不止一种导航栏/按钮/标题样式出现 应用程序)所以我不是在寻找只能通过 外观代理...

  • 我已在调试视图层次结构中检查了“完成”按钮 转换之前和之后的相同实例

  • 我试图在pop

  • 之后重新应用色调颜色
  • 我不会在流程中的任何位置应用字体粗细

  • 另外,在我看来,字体和字体大小似乎没有变化 过程。

在ViewController A中

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    ...
    self.navigationController?.pushViewController(vcB, animated: true)
    ...

在ViewController B中

viewDidLoad() {
    ...
    let backButton = UIBarButtonItem(image: UIImage(named: "arrowLeft"), style: .plain, target: self, action: #selector(goBack))
    backButton.tintColor = CMPThemes.popoverNavigationBarItemColour()
    self.navigationItem.leftBarButtonItem  = backButton
}

故事板看起来像:(我已将A和B添加到图像中以保持清晰度)。

enter image description here

如果有人意识到这个问题并且可以指出我正确的方向进行修复,那就太棒了!

2 个答案:

答案 0 :(得分:1)

我发现了问题。应用的色调颜色不是问题。我认为,最初当它从故事板加载完成按钮时,doneButton样式等于 .done ,稍后当你弹出到ViewControllerA时,样式会以某种方式变为 .plan < / strong>,所以我认为在色调下面设置样式应该可以解决问题。

尝试使用以下代码更新ViewControllerA中的viewWillAppear方法:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    doneButton.tintColor = [CMPThemes navigationBarItemColour]; // it's a blue
    doneButton.style = .done
}

希望它有所帮助!

答案 1 :(得分:0)

我遇到过同样的问题。

我有后退按钮自定义图像,当我按下视图控制器并按回来时它将变为粗体(默认图像)

所以我在storyboard中所做的就是将单个BLANK空间应用于后退按钮

第1步

- &GT;点击导航项

enter image description here

第2步

- &GT;在后退按钮上放置空格

enter image description here

现在你可以观察到

导航项目有一个空白项目

enter image description here