将 IBOutlet 按钮放入数组时发出警告
Warning whilst putting IBOutlet buttons in an array
我试图将 9 个按钮放入一个数组中,但出现错误
Cannot use instance member 'oneOne' within property initializer; property initializers run before 'self' is available
每个按钮 9 次,这是我的代码。我将不胜感激任何帮助,我是 iOS 开发的新手。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet var oneOne: UIButton!
@IBOutlet var twoOne: UIButton!
@IBOutlet var threeOne: UIButton!
@IBOutlet var oneTwo: UIButton!
@IBOutlet var twoTwo: UIButton!
@IBOutlet var threeTwo: UIButton!
@IBOutlet var oneThree: UIButton!
@IBOutlet var twoThree: UIButton!
@IBOutlet var threeThree: UIButton!
var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
谢谢
为 allSpaces
使用 lazy var
声明或创建 @IBOutlet
集合:
lazy var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
或:
@IBOutlet weak var buttons: [UIButton]! // Connect your outlets here.
我试图将 9 个按钮放入一个数组中,但出现错误
Cannot use instance member 'oneOne' within property initializer; property initializers run before 'self' is available
每个按钮 9 次,这是我的代码。我将不胜感激任何帮助,我是 iOS 开发的新手。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet var oneOne: UIButton!
@IBOutlet var twoOne: UIButton!
@IBOutlet var threeOne: UIButton!
@IBOutlet var oneTwo: UIButton!
@IBOutlet var twoTwo: UIButton!
@IBOutlet var threeTwo: UIButton!
@IBOutlet var oneThree: UIButton!
@IBOutlet var twoThree: UIButton!
@IBOutlet var threeThree: UIButton!
var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
谢谢
为 allSpaces
使用 lazy var
声明或创建 @IBOutlet
集合:
lazy var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
或:
@IBOutlet weak var buttons: [UIButton]! // Connect your outlets here.