gpt4 book ai didi

ios - 属性初始值不变

转载 作者:行者123 更新时间:2023-11-28 07:16:34 25 4
gpt4 key购买 nike

我有一个 BaseViewController,它有一个名为 hideStatusBar 的 boolean 属性,初始化为 false

import Foundation
import UIKit

class BaseViewController: UIViewController {

var hideStatusBar: Bool = false

override func prefersStatusBarHidden() -> Bool {
return hideStatusBar
}

}

在派生自该基类的子类中,我将hideStatusBar 的值设置为true。但它似乎并没有改变值(value)。我在 prefersStatusBarHidden 方法中仍然得到 false。

这个方法当然有效。我更改了属性的值,包括 true 和 false 并进行了测试。

如何才能让它发挥作用?

最佳答案

以下代码应该适用于您的 BaseViewController 子类:

import UIKit

class SubViewController: ViewController {

override func awakeFromNib() {
hideStatusBar = false
}

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

/*
override func prefersStatusBarHidden() -> Bool {
return hideStatusBar
}
*/

}

关于ios - 属性初始值不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25642155/

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