图像未在父类Swift中更新

问题描述 投票:0回答:1

我已创建BaseViewController以实现可重用性。有顶。 BaseViewController中的横幅图像。我正在尝试从孩子那里修改它,但是它不起作用。

BaseVC:

import UIKit
import SnapKit
class BaseViewController: UIViewController {

    public let bannerImageView = UIImageView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        self.view.addSubview(bannerImageView)

        bannerImageView.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(self.view)
            make.height.equalTo(200)
        }
        self.view.backgroundColor = .white
        self.navigationController?.navigationBar.isHidden = true

    }

}

HomeViewController:

import UIKit

class HomeViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

    }

    override func viewWillAppear(_ animated: Bool) {
         self.bannerImageView.image = UIImage(named: "HomeTopBanner")

    }

}
ios swift uiimageview
1个回答
0
投票

[当您在子类中重写方法时,应像这样调用super方法。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated) 
    self.bannerImageView.image = UIImage(named: "HomeTopBanner")
}
© www.soinside.com 2019 - 2024. All rights reserved.