gpt4 book ai didi

ios - 导航栏颜色未保存

转载 作者:可可西里 更新时间:2023-11-01 01:24:40 26 4
gpt4 key购买 nike

我有带有两个不同导航栏的 View Controller 。每个导航栏都有不同的颜色。

VC1 and VC2

如果我从 VC1 移到 VC2,我会看到不同的颜色,但如果移回,我会在 VC2 的 VC1 导航栏中看到颜色。

View Controller 1 Returned

所以 VC1 的导航栏颜色没有正确保存

VC1:

import UIKit

class TableViewController_1: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor(red: 56.0/255.0, green: 208.0/255.0, blue: 125.0/255.0, alpha: 1.00)

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

VC2:

import UIKit

class TableViewController_2: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor(red: 105.0/255.0, green: 28.0/255.0, blue: 56.0/255.0, alpha: 1.00)

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

如何在VC1中固定导航条颜色?谢谢你的帮助!

最佳答案

不要在 viewDidLoad 中更改导航栏的颜色,而是在 viewWillAppear 中执行:

VC1

override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.barTintColor = UIColor(red: 56.0/255.0, green: 208.0/255.0, blue: 125.0/255.0, alpha: 1.00)
}

VC2

override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.barTintColor = UIColor(red: 105.0/255.0, green: 28.0/255.0, blue: 56.0/255.0, alpha: 1.00)
}

关于ios - 导航栏颜色未保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42051958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com