gpt4 book ai didi

swift - 覆盖 Swift 中的属性

转载 作者:行者123 更新时间:2023-12-04 14:00:40 26 4
gpt4 key购买 nike

我有一个像下面这样的类(class)

 class MainVC: UIViewController {

lazy var someBtn: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.isHidden = true
button.addTarget(self, action: #selector(didPressBtn), for: .touchUpInside)
return button
}()
}

我继承了 MainVC,当我尝试覆盖 someBtn 时,错误消息显示为 Getter for 'someBtn' with Objective-C selector 'someBtn' conflicts with getter for 'someBtn' from superclass 'MainVC' with the same Objective-C selector
class SecondVC: MainVC {
override var someBtn:UIButton = {
return UIButton()
}
}

最佳答案

你可以做一点改变:

class MainVC: UIViewController {
lazy var someBtn: UIButton = createB()

func createB() -> UIButton{
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.isHidden = true
return button
}
}

class SecondVC: MainVC{
override func createB() -> UIButton {
return UIButton()
}
}
property进入 method

关于swift - 覆盖 Swift 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48009798/

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